-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshodan_ext.py
69 lines (57 loc) · 1.87 KB
/
shodan_ext.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
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
63
64
65
66
67
68
69
import shodan
import argparse
import re
SHODAN_API_KEY = ""
file = open('shodan.txt', 'w')
ip = []
url = []
api = shodan.Shodan(SHODAN_API_KEY)
parser = argparse.ArgumentParser(description='Look for info in Shodan')
parser.add_argument('-d', dest='domain',nargs='+', help='Domains/IP to lookup in Shodan')
parser.add_argument('-f', dest='filename', help='Path to load file with ips and domains')
args = parser.parse_args()
if args.filename is not None:
with open(args.filename) as f:
domain_list = f.readlines()
else:
domain_list = args.domain
for domain in domain_list:
pat_ip = re.compile("^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
isIP = pat_ip.match(domain)
if isIP:
ip.append(domain)
print "IP: %s" % domain
else:
url.append(domain)
print "URL: %s" % domain
# Wrap the request in a try/ except block to catch errors
try:
# Search Shodan
for dom in url:
results = api.search('dom')
# Show the results
for result in results['matches']:
print 'IP: %s' % result['ip_str']
print "Organization: %s" % result.get('org', 'n/a')
print "Operating System: %s" % result.get('os', 'n/a')
# Print all banners
for item in result['data']:
print "Port: %s" % item['port']
print "Banner: %s" % item['data']
print ''
except shodan.APIError, e:
print 'Error: %s' % e
try:
# Lookup the host
for i in ip:
host = api.host(i)
# Print general info
print "IP: %s" % host['ip_str']
print "Organization: %s" % host.get('org', 'n/a')
print "Operating System: %s" % host.get('os', 'n/a')
# Print all banners
for item in host['data']:
print "Port: %s" % item['port']
print "Banner: %s" % item['data']
except shodan.APIError, e:
print 'Error: %s' % e