@@ -0,0 +1,1719 @@
+import re%0Aimport sys%0Aimport os%0Aimport pprint%0A%0Aimport click%0A%0Atry:%0A    import shodan%0Aexcept ImportError:%0A    print('Install shodan: pip install shodan')%0A    sys.exit(0)%0A%0A%0ASHODAN_API_KEY = os.environ%5B'SHODAN_API_KEY'%5D%0A%0A%0Adef get_headers(text):%0A    header_string = re.findall(%0A        '%5E(.*?)(?:%5B%5Cr%5Cn%5D%7B3,4%7D)', text, flags=re.DOTALL %7C re.I%0A    )%0A    if not header_string:%0A        return None%0A%0A    data = %7B%7D%0A    for line in header_string%5B0%5D.splitlines():%0A        match = re.findall('%5E(.*?):(.*)', line)%0A%0A        if match:%0A            key, value = map(lambda v: v.strip(), match%5B0%5D)%0A            data%5Bkey%5D = value%0A%0A    return data%0A%0A%0A@click.command()%0A@click.option(%0A    '--filter',%0A    default=None,%0A    type=str,%0A    help='Filter by header'%0A)%0A@click.option(%0A    '--stats',%0A    default=False,%0A    is_flag=True,%0A    help='Include stats'%0A)%0A@click.argument('query')%0Adef main(filter, stats, query):%0A    counter = 0%0A    filtered_header = %5B%5D%0A    api = shodan.Shodan(SHODAN_API_KEY)%0A%0A    try:%0A        result = api.search(query)%0A    except shodan.exception.APIError:%0A        print('%5B-%5D API connection error.')%0A        sys.exit(0)%0A%0A    for match in result%5B'matches'%5D:%0A        hd = get_headers(match%5B'data'%5D)%0A        if not hd:%0A            continue%0A%0A        if filter:%0A            value = hd.get(filter)%0A            if value:%0A                filtered_header.append(value)%0A        else:%0A            pprint.pprint(hd, width=160)%0A            counter += 1%0A%0A    if filtered_header:%0A        pprint.pprint(filtered_header, width=160)%0A%0A    if stats:%0A        print()%0A        print('%5B+%5D n_matches: %7B%7D'.format(len(result%5B'matches'%5D)))%0A        print('%5B+%5D n_printed: %7B%7D'.format(counter or len(filtered_header)))%0A%0A%0Aif __name__ == '__main__':%0A    main()%0A

Add shodan script to get page headers to test plugins