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

Function stream

shodan/__main__.py:636–794  ·  view source on GitHub ↗

Stream data in real-time.

(streamer, fields, separator, datadir, asn, alert, countries, custom_filters, ports, tags, vulns, limit, compresslevel, timeout, color, quiet)

Source from the content-addressed store, hash-verified

634@click.option('--color/--no-color', default=True)
635@click.option('--quiet', help='Disable the printing of information to the screen.', is_flag=True)
636def stream(streamer, fields, separator, datadir, asn, alert, countries, custom_filters, ports, tags, vulns, limit, compresslevel, timeout, color, quiet):
637 """Stream data in real-time."""
638 # Setup the Shodan API
639 key = get_api_key()
640 api = shodan.Shodan(key)
641
642 # Temporarily change the baseurl
643 api.stream.base_url = streamer
644
645 # Strip out any whitespace in the fields and turn them into an array
646 fields = [item.strip() for item in fields.split(',')]
647
648 if len(fields) == 0:
649 raise click.ClickException('Please define at least one property to show')
650
651 # The user must choose "ports", "countries", "asn" or nothing - can't select multiple
652 # filtered streams at once.
653 stream_type = []
654 if ports:
655 stream_type.append('ports')
656 if countries:
657 stream_type.append('countries')
658 if asn:
659 stream_type.append('asn')
660 if alert:
661 stream_type.append('alert')
662 if tags:
663 stream_type.append('tags')
664 if vulns:
665 stream_type.append('vulns')
666 if custom_filters:
667 stream_type.append('custom_filters')
668
669 if len(stream_type) > 1:
670 raise click.ClickException('Please use --ports, --countries, --custom, --tags, --vulns OR --asn. You cant subscribe to multiple filtered streams at once.')
671
672 stream_args = None
673
674 # Turn the list of ports into integers
675 if ports:
676 try:
677 stream_args = [int(item.strip()) for item in ports.split(',')]
678 except ValueError:
679 raise click.ClickException('Invalid list of ports')
680
681 if alert:
682 alert = alert.strip()
683 if alert.lower() != 'all':
684 stream_args = alert
685
686 if asn:
687 stream_args = asn.split(',')
688
689 if countries:
690 stream_args = countries.split(',')
691
692 if tags:
693 stream_args = tags.split(',')

Callers

nothing calls this directly

Calls 7

get_api_keyFunction · 0.90
timestrFunction · 0.90
open_streaming_fileFunction · 0.90
get_banner_fieldFunction · 0.90
escape_dataFunction · 0.90
_create_streamFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected