-
-
Notifications
You must be signed in to change notification settings - Fork 792
/
shodan.php
62 lines (49 loc) · 1.1 KB
/
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
55
56
57
58
59
60
61
62
<?php
function usage( $err=null ) {
echo 'Usage: '.$_SERVER['argv'][0]." <search> [shodan_api_key]\n";
if( $err ) {
echo 'Error: '.$err."\n";
}
exit();
}
if( $_SERVER['argc']<2 || $_SERVER['argc']>3 ) {
usage();
}
if( $_SERVER['argc'] == 3 ) {
$_api_key = trim($_SERVER['argv'][2]);
} else {
$_api_key = getenv('SHODAN_KEY');
}
if( !$_api_key ) {
usage('API key nmot found');
}
$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, check your API key!\n" );
}
$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();
?>