@@ -246,8 +246,13 @@ def __init__(self):
246
246
"dns: ip lookup" : self .to_a_record ,
247
247
"dns: mx lookup" : self .to_mx_records ,
248
248
"dns: txt lookup" : self .to_txt_records ,
249
- "dns: ns lookup" : self .to_ns_records
249
+ "dns: ns lookup" : self .to_ns_records ,
250
250
}
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 })
251
256
252
257
def is_valid_domain (self , _input : str ):
253
258
"""Checks if _input is a domain"""
@@ -283,6 +288,21 @@ def to_ns_records(self, domain: str):
283
288
except Exception as e :
284
289
raise e
285
290
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
+
286
306
class InputValidator (object ):
287
307
"""Handler to validate user inputs"""
288
308
def __init__ (self ):
0 commit comments