-
Notifications
You must be signed in to change notification settings - Fork 6
/
demoShodanSearch.py
63 lines (48 loc) · 1.87 KB
/
demoShodanSearch.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
#!/usr/bin/env python
import shodan
import argparse
import socket
SHODAN_API_KEY = ""
api = shodan.Shodan(SHODAN_API_KEY)
parser = argparse.ArgumentParser(description='Shodan search')
# Parámetros
parser.add_argument("-target", dest="target", help="target IP / domain", required=True)
parser.add_argument("-search", dest="search", help="search", required=None)
parsed_args = parser.parse_args()
hostname = socket.gethostbyname(parsed_args.target)
# Realizar la solicitud en un bloque try / except para detectar errores
try:
# Buscar en Shodan con el objeto api
results = api.search(parsed_args.search)
# mostrar los resultados
print('Resultados: %s' % results['total'])
for result in results['matches']:
print('IP: %s' % result['ip_str'])
print(result['data'])
print('')
except shodan.APIError as exception:
print('Error: %s' % exception)
# Realizar la solicitud en un bloque try / except para detectar errores
try:
# Buscar en Shodan con el objeto api
results = api.count(parsed_args.search)
# mostrar los resultados
print('Resultados: %s' % results['total'])
for result in results['matches']:
print('IP: %s' % result['ip_str'])
print(result['data'])
print('')
except shodan.APIError as exception:
print('Error: %s' % exception)
#Busqueda por host
host = api.host(hostname)
# Info general
print("""
IP: %s
Organization: %s
Operating System: %s
""" % (host['ip_str'], host.get('org', 'n/a'), host.get('os', 'n/a')))
# Imprimir banners
for item in host['data']:
print("""Port: %s
Banner: %s""" % (item['port'], item['data']))