A python class to search ip2asn information for matches.
See the pretty documentation over on readthedocs.
Using pip or pipx:
pipx install ip2asn
ip2asn -f ip2asn.db --fetch
# ip2asn 8.8.8.8
Address: 8.8.8.8
Numeric ip: 134744072
ASN: 15169
Owner: GOOGLE - Google LLC
Country: US
ip_range: 8.8.8.0 - 8.8.8.255
# ip2asn -a 15169
ASN: 15169
Owner: GOOGLE
Country: US
ip_range: 8.8.4.0 - 8.8.4.255
ASN: 15169
Owner: GOOGLE
Country: US
ip_range: 8.8.8.0 - 8.8.8.255
ASN: 15169
Owner: GOOGLE
...
(google has a lot of registrations)
# ip2asn -T -a 15169
( net 8.8.4.0/24 or net 8.8.8.0/24 or net 8.35.200.0/21 or ....
import ip2asn
i2a = ip2asn.IP2ASN("ip2asn-v4-u32.tsv")
result = i2a.lookup_address("93.184.216.34")
import pprint
pprint.pprint(result)
Produces:
{'ASN': '15133',
'country': 'US',
'ip_numeric': 1572395042,
'ip_range': [1572394752, 1572396543],
'ip_text': '93.184.216.34',
'owner': 'EDGECAST - MCI Communications Services, Inc. d/b/a Verizon Business'}
import ip2asn
i2a = ip2asn.IP2ASN("ip2asn-combined.tsv")
results = i2a.lookup_asn(15169, limit=2) # limit is optional
import pprint
pprint.pprint(results)
``**
**Produces:**
``` text
[{'ASN': '15169',
'country': 'US',
'ip_range': [134743040, 134743295],
'owner': 'GOOGLE - Google LLC'},
{'ASN': '15169',
'country': 'US',
'ip_range': [134744064, 134744319],
'owner': 'GOOGLE - Google LLC'}]
Wes Hardaker, USC/ISI