IP to ASN Mapping with Python

In the previous post, I showed how to use Python to perform a GeoLocation lookup for a list of IP addresses. However, sometimes it is desirable to know the ISP of the IP Address as well.  This is where the IP to ASN Mapping Service hosted by www.team-cymru.org is of tremendous value. They offer multiple ways to query their database, and the Python program shown below uses the DNS option.

I should note that this program was inspired by the “WhereIs [IP] Country Lookup” tool hosted by the SANS Internet Storm Center, which also accesses the data set hosted by Team Cymru.

A couple of notes about the SimpleAsnIP.py program.  This program uses the same list of IP addresses as was discussed in the previous post about SimpleGeoIP.py.  The documentation at http://www.team-cymru.org/Services/ip-to-asn.html discusses how to use the DNS Service.  This program essentially reverses the order of each octet in the list of IP addresses to be queried and uses that to construct a dig query to perform a lookup for each address in the IPListFile.  If the DNS Server does not respond for a specific IP address, it will be written to the log file pointed to by the IP_ASN_err parameter.

SimpleGeoIP.py

Tagged , , . Bookmark the permalink.
  • The postings and views on this site are my own and do not necessarily reflect the positions, strategies, or opinions of any current or previous employer.