top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

GeoIP2 for retrieving city and region using Python

+1 vote
465 views

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 "", line 1, in 
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?

posted Jul 12, 2013 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button
I did, for me it gives exact city location and not the ISP's city location.

I dont know what for you it just says Kansas, it shouldn't, since it  using longitude and latitude, it should have been accurate.
I suggest you read that geoiptool site, in particular the page
http://www.geoiptool.com/en/ip_info/
There is some misinformation, but notice carefully the part about  dynamic IP addresses. Probably 99% of the individual users on the web (the ones using a browser) have dynamic IP addresses. The fixed ones are needed by servers, and especially for DNS use, where the name lookup wants to be stable for relatively log periods of time.

Similar Questions
0 votes

Please give me some idea about how we can query the DNS
How you have divided the passive dns functioning into two parts as recursor and resolver.
Can you please give some idea about how they function, and when they are employed after the query is submitted to the pdns
How the data packet will be analyzed for ddos attack.

+1 vote

I am Automating some repetitive works through Sikuli and Python scripting languages. I have multiple workflows. I need to schedule this script for every two hours. Can anyone guide me how to schedule the scripts for every two hours.

Is there any way to schedule the python programming through Task scheduler in windows platform.

My environment
OS:Windows
Programming languages: Sikuli,Python

+2 votes

As per my understanding Receive system calls will be a blocking call of the code... it will not go ahead unless it receives the response from client .. my question is how would i set time in that? i want my code should wait only for few seconds then it has to come out from that

...