MCPcopy Create free account
hub / github.com/achillean/shodan-python / host

Function host

shodan/__main__.py:328–355  ·  view source on GitHub ↗

View all available information for an IP address

(format, history, filename, save, ip)

Source from the content-addressed store, hash-verified

326@click.option('--save', '-S', help='Save the host information in the a file named after the IP (append if file exists).', default=False, is_flag=True)
327@click.argument('ip', metavar='<ip address>')
328def host(format, history, filename, save, ip):
329 """View all available information for an IP address"""
330 key = get_api_key()
331 api = shodan.Shodan(key)
332
333 try:
334 host = api.host(ip, history=history)
335
336 # Print the host information to the terminal using the user-specified format
337 HOST_PRINT[format](host, history=history)
338
339 # Store the results
340 if filename or save:
341 if save:
342 filename = '{}.json.gz'.format(ip)
343
344 # Add the appropriate extension if it's not there atm
345 if not filename.endswith('.json.gz'):
346 filename += '.json.gz'
347
348 # Create/ append to the file
349 fout = helpers.open_file(filename)
350
351 for banner in sorted(host['data'], key=lambda k: k['port']):
352 if 'placeholder' not in banner:
353 helpers.write_banner(fout, banner)
354 except shodan.APIError as e:
355 raise click.ClickException(e.value)
356
357
358@main.command()

Callers

nothing calls this directly

Calls 2

hostMethod · 0.95
get_api_keyFunction · 0.90

Tested by

no test coverage detected