December 2018
Intermediate to advanced
226 pages
4h 57m
English
While working with the BGP routing protocol , a network engineer often faces a challenge to identify the ASN of a given public IP or hostname or DNS name. Let's see a sample code that we can use to fetch the details for any IP address.
We'll use the cymruwhois Python library for this purpose.
The code is as follows:
import socketdef getfromhostname(hostname): print ("AS info for hostname :"+hostname) ip = socket.gethostbyname(hostname) from cymruwhois import Client c=Client() r=c.lookup(ip) print (r.asn) print (r.owner)def getfromip(ip): print ("AS info for IP : "+ip) from cymruwhois import Client c=Client() r=c.lookup(ip) print (r.asn) print (r.owner)getfromhostname("microsoft.com")getfromip("216.58.192.14") ...Read now
Unlock full access