python - What is the equivalent of PHP's geoip_isp_by_name function? -
i need equivalent of geoip_isp_by_name. using django geoip module.
i search lot , couldn't find function. please advise.
pygeoip has support isp lookup using geoip database.
# found under /usr/share/geoip/{geoip,geoipv6}.dat gi = pygeoip.geoip('/path/to/geoipisp.dat') gi.org_by_name('cnn.com') 'turner broadcasting system' the installation process of geoip database depends on operating system , distro. it's available in favorite distro's repository under geoip-database. more information take @ geoip country database installation instructions
sadly, not work, got error on both ubuntu 12.10 , debian 6 installation, i'm not sure if geoip database corrupt or module broken. might have better luck.
gi.org_by_name("cnn.com") traceback (most recent call last): file "<input>", line 1, in <module> file "/usr/local/lib/python2.7/dist-packages/pygeoip/__init__.py", line 548, in org_by_name return self.org_by_addr(addr) file "/usr/local/lib/python2.7/dist-packages/pygeoip/__init__.py", line 531, in org_by_addr raise geoiperror(message) geoiperror: invalid database type, expected org, isp or asnum update: since geoip wouldn't work (see comments), played around little bit use of tracer sites. got hacky solution works both ips , hostnames. should not used permanent solution, works fine.
import html2text import re import urllib2 lookup = "thevoid.no" # accepts both hostname , ip tracer = "http://www.ip-adress.com/ip_tracer/" pat = "isp of ip \[\?\]:\n\n([a-za-z ]+)" hdr = {'user-agent': 'mozilla/5.0'} # ip-adress.com doesn't accept python req = urllib2.request(tracer + lookup, headers=hdr) page = urllib2.urlopen(req).read() h = html2text.html2text() h.ignore_links = true text = h.handle(page) try: # hetzner online ag print re.search(pat, text).group(1) except: print "could not find isp for", lookup update 2: got answer issue. there's seperate geoip databases, , org edition can found here, seem cost money. i'm not sure if there's free alternative in python, or sharing api. if not, hacky solution might it.
Comments
Post a Comment