import pygeoip code example
Example 1: python pygeoip example
def count_ref_ipPerAsn(ref=None):
gi = pygeoip.GeoIP("../lib/GeoIPASNum.dat")
if ref is None:
ref = pickle.load(open("./saved_references/56d9b1eab0ab021d00224ca8_routeChange.pickle","r"))
ipPerAsn = defaultdict(set)
for targetRef in ref.values():
for router, hops in targetRef.iteritems():
for hop in hops.keys():
if hop != "stats":
ipPerAsn[asn_by_addr(hop,gi)[0]].add(hop)
return ipPerAsn
Example 2: python pygeoip example
>>> gi = pygeoip.GeoIP('GeoIPISP.dat')
>>> gi.isp_by_name('cnn.com')
'Turner Broadcasting System'