-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshodan_helper.py
More file actions
46 lines (39 loc) · 1.07 KB
/
shodan_helper.py
File metadata and controls
46 lines (39 loc) · 1.07 KB
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
#
# Look up shodan.io data for an IP address
# Author: N. Beckstead
# TODO: Handle None returns
#
import shodan
from server_vars import SHODAN_KEY
api = shodan.Shodan(SHODAN_KEY)
def lookup_host(ip):
try:
host = api.host(ip)
except shodan.APIError:
return "API Error"
rt_string = """
<strong>IP: {}</strong>
Organization: {}
Operating System: {}
""".format(host['ip_str'], host.get('org', 'n/a'), host.get('os', 'n/a'))
for item in host['data']:
rt_string += """
<strong>Port: {}</strong>
<strong>Banner:</strong> {}\n\n
""".format(item['port'], item['data'])
rt_string = rt_string.replace('\n', '<br>')
return rt_string
def get_coordinates(ip):
lat = None
lon = None
try:
host = api.host(ip)
except shodan.APIError:
return None
try:
for item in host['data']:
lat = item['latitude']
lon = item['longitude']
except KeyError:
return None
return (lat, lon)