-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshodanapi.py
More file actions
60 lines (47 loc) · 1.79 KB
/
shodanapi.py
File metadata and controls
60 lines (47 loc) · 1.79 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# ----------------------------------------
# Shodan API method lookups
# ----------------------------------------
import requests
import os
# Base URL
baseURL = "https://api.shodan.io"
def cve(cveStr: str):
cve = requests.get(f"https://cvedb.shodan.io/cve/{cveStr}").json()
print("=" * 120)
print(f"CVE Summary: {cve["summary"]}")
print("=" * 120)
print(f"Reference: {cve["references"][0]}")
def search(q: str):
apikey = os.getenv("SHODAN_API_KEY")
r: dict = requests.get(
f"{baseURL}/shodan/host/search?key={apikey}&query={q}"
).json()
print(f"Total Results: {r.get('total', 0)}")
for m in r.get("matches", []):
ip = m.get("ip_str", "N/A")
port = m.get("port", "N/A")
product = m.get("product", "Unknown")
org = m.get("org", "Unknown")
print(f"IP: {ip}:{port}")
print(f"Product: {product}")
print(f"Organization: {org}")
print("-" * 40)
def iplookup(ip: str):
apikey = os.getenv("SHODAN_API_KEY")
r: dict = requests.get(f"{baseURL}/shodan/host/{ip}?key={apikey}").json()
print(f"IP: {r.get('ip_str', 'N/A')}")
print(f"Organization: {r.get('org', 'N/A')}")
print(f"Operating System: {r.get('os', 'N/A')}")
for port in r.get("ports", []):
print(f"Open port: {port}")
def api_info():
apikey = os.getenv("SHODAN_API_KEY")
r: dict = requests.get(f"{baseURL}/api-info?key={apikey}").json()
print(f"Shodan API Plan: {r.get("plan", "N/A")}")
print(f"Scan Credits: {r.get('scan_credits', "N/A")}")
print(f"Queries Remaining: {r.get('query_credits', "N/A")}")
print(f"Number of IP's Monitored: {r.get("monitored_ips")}")
def myip():
apikey = os.getenv("SHODAN_API_KEY")
r: dict = requests.get(f"{baseURL}/tools/myip?key={apikey}").json()
print(f"{r}")