Created
October 11, 2022 22:58
-
-
Save ssnkhan/0629125c76ab821513c39d2cbe2b37d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Uses Shadowserver's `ASN and Network Queries` API | |
# See https://www.shadowserver.org/what-we-do/network-reporting/api-asn-and-network-queries/ | |
# Preferred over similar free services as it offers better normalisation of ASN Names | |
# Beware of rate limiting, 10 queries/second | |
import json | |
import requests | |
def get_whois(ip): | |
url = "https://api.shadowserver.org/net/asn?origin=" + ip | |
response = requests.get(url).json() | |
asn = int(response[0].get("asn")) | |
asn_name = response[0].get("asname_long").rstrip(".") | |
asn_short = response[0].get("asname_short") | |
bgp_prefix = response[0].get("prefix") | |
country = response[0].get("geo") | |
return asn, asn_name, asn_short, bgp_prefix, country |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment