GeoIP2 for retrieving city and region ?

Νικόλας nikos at superhost.gr
Fri Jul 12 16:18:20 CEST 2013


Hello, iam still looking for a way to identify the city of my website 
visitors.

The closet i have gone is to come up with the visitor's ISP city:

try:
	gi = pygeoip.GeoIP('/usr/local/share/GeoLiteCity.dat')
	city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] )
	host = socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0]
except Exception as e:
	host = repr(e)


But today i was searching again for this and found out about geoip2, 
maybe that would help more.


 >>> import geoip2
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ImportError: No module named 'geoip2'


     >>> client = geoip2.webservices.Client(42, 'abcdef123456')
     >>> omni = client.omni('24.24.24.24')
     >>> country = omni.country
     >>> print(country.iso_code)


I cant even import the module even though my 'pip install geopip2' was 
successful

There is definately i way to identify the users location based solely on 
its ip address as this site does it: http://www.geoiptool.com/

Google, MS, facebook and twitter are not the only ones that can do it?

Perhaps this is being done by giving  longitude and latitude?
-- 
What is now proved was at first only imagined!



More information about the Python-list mailing list