Skip to content

Instantly share code, notes, and snippets.

@n0x08
Last active February 25, 2021 11:09
Show Gist options
  • Select an option

  • Save n0x08/7ffeeb3d59ebc8aab2942e361905c12d to your computer and use it in GitHub Desktop.

Select an option

Save n0x08/7ffeeb3d59ebc8aab2942e361905c12d to your computer and use it in GitHub Desktop.

Revisions

  1. n0x08 revised this gist Oct 11, 2018. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions gnMonthlyInfected.py
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,13 @@

    asn = sys.argv[1]

    print("Looking up "+ str(asn))

    asrankraw = requests.get('http://as-rank.caida.org/api/v1/asns/' + asn.split('AS')[1])
    asrank = asrankraw.json()

    print("Finding infection stats for " + asrank['data']['org']['name'])

    asnraw = requests.get('https://research.api.greynoise.io/v2/infections/asn/' + asn, headers = headers) #V2 IP API lookup
    asndata = asnraw.json()

  2. n0x08 revised this gist Oct 11, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gnMonthlyInfected.py
    Original file line number Diff line number Diff line change
    @@ -31,4 +31,5 @@
    sorted_tags.sort(key=lambda x: x[1])
    sorted_tags.reverse()

    pprint(sorted_tags)
    pprint(sorted_tags)
    print("Total infected hosts in " + str(asn) + ": " + str(sum(n for _, n in sorted_tags)))
  3. n0x08 created this gist Oct 11, 2018.
    34 changes: 34 additions & 0 deletions gnMonthlyInfected.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    # !/usr/bin/env python
    # gnMonthlyInfected.py
    #
    # Report statistics on monthly infections
    # in a specified Autonomous System as seen
    # by Greynoise.io
    #
    # Requires: Greynoise API key
    #
    # Example: python3 gnMonthlyInfected.py AS12345
    #
    import sys
    import json
    import requests
    from collections import Counter, defaultdict
    from pprint import pprint

    headers = {'key': 'GREYNOISE API KEY GOES HERE'}

    asn = sys.argv[1]

    asnraw = requests.get('https://research.api.greynoise.io/v2/infections/asn/' + asn, headers = headers) #V2 IP API lookup
    asndata = asnraw.json()

    tagstats = defaultdict(int)

    for i in asndata:
    tagstats[str(i['tag_name'])] += 1

    sorted_tags = [x for x in tagstats.items()]
    sorted_tags.sort(key=lambda x: x[1])
    sorted_tags.reverse()

    pprint(sorted_tags)