Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,270
    Rep Power
    12

    GeoIP2 for retrieving precise city location?


    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?

    Can you please tell me how its being done in python 3.3.x

    Thank you.
    What is now proved was once only imagined!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    11
    Originally Posted by Nik
    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/
    I guess you didn't read my previous post. These tools only differ in the degree of wrongness they provide. They are completely unaware of network address block transfers. So if a Russian telecom company get assigned a block that belonged to NTT last month, geoiptool will report that I'm not even in the correct country for quite a long time.

    Its better than nothing, but its not good enough to rely on. If you really want to track your customers you're going to have to get them to agree to report their locations to you. Retail companies do this with customer point-card systems. Tracking you is in the terms of the point card agreement (that nobody reads). Lots of websites do this by having users register their address when they log in (and then backstopping that information against something like geoip -- compare the two; if they match then you're more certain).

    Let's give this a test. Right now I am in Nakagami, Okinawa. geoiptool.com just told me that I am in Marugame, Kagawa -- which is about 2000 miles and several state-sized islands wrong. That's like reporting that someone in actually in Dallas, Texas is looking at your site from Washington, D.C. or that someone actually in London is looking at your site from Frankfurt.
    Last edited by zxq9; July 12th, 2013 at 05:33 PM.
  4. #3
  5. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,270
    Rep Power
    12
    I have read all your answer very carefully but i still need some way of getting it done.
    All my Greek website visitors say they are from Europe/Athens which is the ISP's location and not user's homeland.

    Well it worked for me but as many other told me it wasn't accurate for them too.

    Please try this: http://www.maxmind.com/en/geoip_demo

    and tell me if maxmind's database can pippont you city's location.

    Thank you.
    What is now proved was once only imagined!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    11
    They got my ISP correct (amazing that anyone gets this wrong since its written in the arpa reverse request...), and though they got closer (off by a few hundred km, not thousands like geoip) they still don't have me meaningfully pinned. The situation might be different if I reconnect and get a different IP -- in fact it almost certainly will be -- but that's what I was talking about before; the only difference is the degree of wrongess not that any geoip locator actually has meaningful data when you want to pinpoint someone by IP.

    Which is why you need multiple sources and rate guesses the way the big guys do. GeoIP is one tool, just one -- so go for a few more.

    How are the visitors coming. Are they registered users? Do you have affiliates? Are they using a native application or browser? Answers to these questions can lead you to partial solutions -- and partial solutions working together can give you a much higher confidence guess than just relying on any single (badly flawed) approach.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Location
    Canada
    Posts
    51
    Rep Power
    1
    I tried maxmind's and I wouldn't give it 100% accuracy, it did get in the same province as me though, about an hour away from me.
  10. #6
  11. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,270
    Rep Power
    12

    Question


    Originally Posted by zxq9
    They got my ISP correct (amazing that anyone gets this wrong since its written in the arpa reverse request...), and though they got closer (off by a few hundred km, not thousands like geoip) they still don't have me meaningfully pinned. The situation might be different if I reconnect and get a different IP -- in fact it almost certainly will be -- but that's what I was talking about before; the only difference is the degree of wrongess not that any geoip locator actually has meaningful data when you want to pinpoint someone by IP.

    Which is why you need multiple sources and rate guesses the way the big guys do. GeoIP is one tool, just one -- so go for a few more.

    How are the visitors coming. Are they registered users? Do you have affiliates? Are they using a native application or browser? Answers to these questions can lead you to partial solutions -- and partial solutions working together can give you a much higher confidence guess than just relying on any single (badly flawed) approach.
    Yes, you are right,

    Actually i dont ask the user any information i just log

    a) the datetime of its each visit
    b) the ip address
    c) the browser
    d) and now that city

    as it can be seen in this part of my site:

    http://superhost.gr/?show=log&page=index.html
    What is now proved was once only imagined!
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    11
    Hrm... consider doing a geographic narrowing by confidence. Compare browser-provided timezone against results from several ip-locator services. Mine says Asia/Tokyo, which is wrong, but its correct as far as that I'm in Japan. Compare this with my browser's recommendation -- still Japan. Compare this with GeoIP -- specific city. Compare with Maxmind -- specific, but different, city.

    So this gives us:
    - Japan 4/4
    - Tokyo 1/4
    - Muragame, Kagawa 1/4
    - Fukuoka, Fukuoka 1/4

    -- but the last two also indicate Southern Japan 2/4

    So you have a strong indication what country I'm in, and a relatively strong indication which region I'm in.

    This gets you a lot closer than you were before, and prevents blind inaccuracy by probabilistically reducing the chances that you're dead wrong, and leaving you with increasingly specific answers that are more than likely right.

    Since all of these methods are (or can be) associated with a lat/long grid coordinate for the location, it would be relatively easy to write a GIS-type query that would tell you "what region is common to all points in [your high-probability list]" and return that as the location result. (I'm familiar with using PostGIS -- but any similar sort of geo-library would work so long as you can make && (x,y) type .queries. I'd be shocked if there wasn't some Google map service/function that returns the smallest region that contains a set of points.)

    Probably 90% of the time this will give you a specific city. The other 10% (like my case) are just fliers that can be adjusted down the more times that person hits the site.
  14. #8
  15. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,270
    Rep Power
    12
    Yes, better it is to use some google service to pinpoint the xtact location.

    can we do that?
    What is now proved was once only imagined!
  16. #9
  17. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,296
    Rep Power
    7170
    Google does not provide an API for geolocation, their recommendation is that you ask the user to provide you with their location. Newer browsers support an automatic way of asking the user to provide you with their location.

    This is explained here: https://developers.google.com/maps/articles/geolocation

    If you are just interested in visitor statistics, you should look at Google Analytics.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  18. #10
  19. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,270
    Rep Power
    12

    Question


    Same networking scheme for me too, dynamic that is.

    Every time the DHCP lease expires or i reboot the router i get a new ip address but every time the link i provided states accurately that my ip address is from Thessaloníki and not Europe/Athens which is were my ISP location is.

    Not to mention that in facebook, no matter the way i'am joining, via smartphone, tablet, laptop it always pinpoints my exact location.

    But yes, i can understand your skepticism.
    An ip address can move anywhere while remaining connected to the same ISP, just like a networking device in the house, remains connected to the same router while changing rooms or even floors, or even buildings.

    But then how do you explain the fact that
    http://www.maxmind.com/en/geoip_demo
    pinpointed Thessaloníki and not Athens and for 2 friends of mine that use the same ISP as me but live in different cities also accurately identified their locations too?
    What is now proved was once only imagined!
  20. #11
  21. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,296
    Rep Power
    7170
    But then how do you explain the fact that
    http://www.maxmind.com/en/geoip_demo
    pinpointed Thessaloníki and not Athens and for 2 friends of mine that use the same ISP as me but live in different cities also accurately identified their locations too?
    The fact that it accurately identified the location of three IP addresses is not a solid foundation on which to base an assessment of the system's accuracy. In this thread alone, you already have two other people telling you that the same service did not correctly identify their location. So based on those 5 samples, the service is accurate 60% of the time.

    How accurate is accurate enough for your application? Is 60% good enough? (5 samples is woefully insufficient to actually judge the accuracy of the service, I suspect it is higher than 60%)

    Do you need the system to work everywhere in the world? It is likely that some services will be able to focus on certain areas of the world better than other services. If you only need a service that works in Greece, maybe you can find one that works better there at the cost of working more poorly in other parts of the world.

    Different providers have different sets of data with different locations for the same addresses. Many locations will be right, and many locations will be wrong. As zxq9 suggested, you could improve the accuracy of your results by combining results from multiple providers.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  22. #12
  23. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,270
    Rep Power
    12
    You are right.
    While FORTHnet ISP works well with maxmind which can pinpoint the visitor's exact location other ISP like Cyta always says Europe/Athens.

    But how is this possible a vistiro from one ISP to be accurately identified and the other not?
    What is now proved was once only imagined!
  24. #13
  25. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,270
    Rep Power
    12
    You are right and i can back this up.

    While FORTHnet ISP(my ISP) works well with maxmind which can pinpoint the visitor's exact location other ISPs like Cyta, OTEnet, HOL always says Europe/Athens.

    So it seems that all boil down to the way the ISP configure its blocks of ip addresses per city.

    All should do the same and then it would be an easy task to accurately identify a visitor by its ip address.
    What is now proved was once only imagined!
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    11
    Originally Posted by Nik
    Yes, better it is to use some google service to pinpoint the xtact location.
    The locations you can get from my example above all come with lat/long coordinates (or retrieving them is easy). Using a mapping service you can create a query that asks "what is the smallest region that contains points [(x1, y1), (x2, y2),...]" and use that as your geolocate answer.

    As E-Oreo says, there is no "here's an IP, give me an answer" type service.
  28. #15
  29. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,270
    Rep Power
    12
    Can you show me please how can i do such a thing for m within a python script?
    What is now proved was once only imagined!
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo