Skip to content

Commit 1d4e01c

Browse files
author
netevert
committed
added shodan hostnames integration
1 parent 94cc246 commit 1d4e01c

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

utils.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,13 @@ def __init__(self):
246246
"dns: ip lookup" : self.to_a_record,
247247
"dns: mx lookup" : self.to_mx_records,
248248
"dns: txt lookup": self.to_txt_records,
249-
"dns: ns lookup" : self.to_ns_records
249+
"dns: ns lookup" : self.to_ns_records,
250250
}
251+
self.api_db = Database()
252+
shodan_api_key = self.api_db.get_api_key("shodan")
253+
if shodan_api_key:
254+
self.shodan_api = shodan.Shodan(shodan_api_key)
255+
self.osint_options.update({"shodan: hostnames": self.to_shodan_hostnames})
251256

252257
def is_valid_domain(self, _input: str):
253258
"""Checks if _input is a domain"""
@@ -283,6 +288,21 @@ def to_ns_records(self, domain: str):
283288
except Exception as e:
284289
raise e
285290

291+
def to_shodan_hostnames(self, domain: str):
292+
"""Searches shodan to discover hostnames associated with the domain"""
293+
try:
294+
data = []
295+
results = self.shodan_api.search("hostname:{}".format(domain))
296+
if results:
297+
for r in results["matches"]:
298+
for h in r["hostnames"]:
299+
data.append(h)
300+
return data
301+
else:
302+
return ["no data available"]
303+
except Exception as e:
304+
return ["shodan api error: ", e]
305+
286306
class InputValidator(object):
287307
"""Handler to validate user inputs"""
288308
def __init__(self):

0 commit comments

Comments
 (0)