Stream data in real-time.
(streamer, fields, separator, datadir, asn, alert, countries, custom_filters, ports, tags, vulns, limit, compresslevel, timeout, color, quiet)
| 634 | @click.option('--color/--no-color', default=True) |
| 635 | @click.option('--quiet', help='Disable the printing of information to the screen.', is_flag=True) |
| 636 | def 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(',') |
nothing calls this directly
no test coverage detected