forked from cehkunal/pentest-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shodan.php
54 lines (42 loc) · 913 Bytes
/
shodan.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
function usage( $err=null ) {
echo 'Usage: '.$_SERVER['argv'][0]." <search>\n";
if( $err ) {
echo 'Error: '.$err."\n";
}
exit();
}
if( $_SERVER['argc'] != 2 ) {
usage();
}
$_api_key = 'xxxxxxxxxxxxxxxxxx';
$search = urlencode( $_SERVER['argv'][1] );
$page = 1;
$run = true;
$t_result = [];
echo "Searching: ".$search."\n\n";
do
{
$url = 'https://api.shodan.io/shodan/host/search?query='.$search.'&page='.$page.'&key='.$_api_key;
echo $url."\n";
$c = file_get_contents( $url );
if( !$c ) {
exit( "Err: cannot connect to Shodan!" );
}
$t_json = json_decode( $c, true );
if( !count($t_json['matches']) ) {
$run = false;
} else {
$t_result = array_merge( $t_result, $t_json['matches'] );
$page++;
//$run = false;
}
}
while( $run );
echo "\n".count($t_result)." results found.\n\n";
foreach( $t_result as $r )
{
echo $r['ip_str'].':'.$r['port']."\n";
}
exit();
?>