-
Notifications
You must be signed in to change notification settings - Fork 7
/
shodan.py
34 lines (24 loc) · 1.55 KB
/
shodan.py
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
#!/usr/bin/env python
import os
import sys
import subprocess
def gather_info(target):
os.system("mkdir ~/Documents/shodan-data/"+target)
print "Query : ip_str,port,org,hostnames,http.title Filter : ssl"
subprocess.call("shodan search --fields ip_str,port,org,hostnames,http.title ssl:%s --color | tee ~/Documents/shodan-data/%s/results-%s.txt" % (target, target, target),shell=True)
print "Query : ip_str,port,org,hostnames,http.title Filter : hostname"
subprocess.call("shodan search --fields ip_str,port,org,hostnames,http.title hostname:%s --color | tee -a ~/Documents/shodan-data/%s/results-%s.txt" % (target, target, target),shell=True)
print "Query : ip_str,port,org,hostnames,http.title Filter : ssl.cert.subject.cn"
subprocess.call("shodan search --fields ip_str,port,org,hostnames,http.title ssl.cert.subject.cn:%s --color | tee -a ~/Documents/shodan-data/%s/results-%s.txt" % (target, target, target),shell=True)
def scan(target):
print "Unique IPs :" #formatting on found data to extract unique IPs
os.system("cat ~/Documents/shodan-data/{}/results-{}.txt | awk {{'print $1'}} | sort -u | tee ~/Documents/shodan-data/{}/ips-{}.txt".format(target,target,target,target))
print "Query : Host " #in-depth scan for unique IPs
subprocess.call("cat ~/Documents/shodan-data/%s/ips-%s.txt | while read line; do shodan host \"$line\"; done | tee -a ~/Documents/shodan-data/%s/portscan-%s.txt" % (target, target, target, target),shell=True)
def open_ports(targets):
print "Open Ports"
def main():
target = sys.argv[1]
gather_info(target)
scan(target)
main()