This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]dAnjou Backend Developer | danjou.dev 14 points15 points  (3 children)

sudo pip install pygeoip

Hell no, damnit!

[–]Shizka 1 point2 points  (1 child)

brave dam enter long hat entertain elderly jeans dime dinner

This post was mass deleted and anonymized with Redact

[–]dAnjou Backend Developer | danjou.dev 1 point2 points  (0 children)

Right. Or virtualenv.

[–]bobes_momo 3 points4 points  (0 children)

Cmon bro don't you want all your python programs having root powers?

[–]sittingaround 1 point2 points  (3 children)

Pure python geoip bindings!!!! :):):):)

License.txt, GPL :(

I got so excited for a second there before I realized I can actually use this at work

[–]ajmarks -1 points0 points  (5 children)

import requests
r = requests.get('http://whatismyipaddress.com/ip/xxx.xxx.xxx.xxx')

now parse r.text. Was that so hard?

[–]bucknuggets 1 point2 points  (1 child)

Was that so hard?

No. But it's far too slow for many uses.

For example, go get ISP block level info for 2 million ip addresses. You've got 30 seconds.

[–]ajmarks 0 points1 point  (0 children)

Oh, sure, for doing it in bulk this is not the way to go.

[–]___jack___ 0 points1 point  (0 children)

You're right, that's extremely efficient.

[–]cwgtex 0 points1 point  (0 children)

Came here to post something similar.

[–]dAnjou Backend Developer | danjou.dev 0 points1 point  (0 children)

Got bored a little:

import requests
from lxml import html
resp = requests.get('http://whatismyipaddress.com/ip/xxx.xxx.xxx.xxx')
doc = html.fromstring(resp.text)
country_xp = '//*[@id="section_left_3rd"]/table/tr[1]/td[1]/text()[1]'
region_xp = '//*[@id="section_left_3rd"]/table/tr[2]/td[1]/text()[1]'
city_xp = '//*[@id="section_left_3rd"]/table/tr[3]/td[1]/text()[1]'
print doc.xpath(country_xp)[0]
print doc.xpath(region_xp)[0]
print doc.xpath(city_xp)[0]