View all available information for an IP address
(format, history, filename, save, ip)
| 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>') |
| 328 | def 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() |
nothing calls this directly
no test coverage detected