GeoIP2 for retrieving city and region ?

Discussion in 'Python' started by Îικόλας, Jul 12, 2013.

  1. 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!
     
    Îικόλας, Jul 12, 2013
    #1
    1. Advertising

  2. Îικόλας

    Dave Angel Guest

    On 07/12/2013 10:18 AM, Îικόλας wrote:
    > Hello, iam still looking for a way to identify the city of my website
    > visitors.
    >

    <SNIP>
    >
    >
    > I cant even import the module even though my 'pip install geopip2' wa
    > successful


    Either it wasn't successful, or it's not the package you thought. There
    are lots of things you might have downloaded, but since you give no
    details...


    >
    > 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/
    >


    Sure, and as long as you don't mind it being 1000 miles off, you too can
    claim to do it too. When I go to that site, the little pin is in
    Kansas, which is 1100 miles from where I live on the east coast of the US.


    > Google, MS, facebook and twitter are not the only ones that can do it?
    >
    > Perhaps this is being done by giving longitude and latitude?


    Or by reading the mind of the programmer.

    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.

    --
    DaveA
     
    Dave Angel, Jul 12, 2013
    #2
    1. Advertising

  3. Στις 12/7/2013 6:32 μμ, ο/η Dave Angel έγÏαψε:
    >
    > 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.



    I did, for me it gives exact city location and not the ISP's city location.

    I dont know whay for you ti just says Kansas, it shoudln't, since it
    susing longitute and latitude, it should have been accurate.

    --
    What is now proved was at first only imagined!
     
    Îικόλας, Jul 12, 2013
    #3
  4. I know i have asked before but hwta i get is ISP city not visitors
    precise city.

    GeoLiteCity.dat isnt accurate that's why it comes for free.
    i must somehow get access to GeoIPCity.dat which is the full version.

    And of course it can be done, i dont want to believe that it cant.

    When visiting http://www.geoiptool.com/en/__ip_info/ it pinpoints my
    _exact_ city of living, not the ISP's.
    It did not even ask me to allow a geop ip javascript to run it present
    sit instantly.

    So, it certainly is possible if only one can find the correct database
    to use.

    So, my question now is, if there is some way we can get an accurate Geo
    City database.

    --
    What is now proved was at first only imagined!
     
    Îικόλας, Jul 12, 2013
    #4
  5. On 2013-07-12, ?????????????? <> wrote:

    > I know i have asked before but hwta i get is ISP city not visitors
    > precise city.


    You can't reliably do that.

    > GeoLiteCity.dat isnt accurate that's why it comes for free. i must
    > somehow get access to GeoIPCity.dat which is the full version.
    >
    > And of course it can be done, i dont want to believe that it cant.


    Believe what you want.

    > When visiting http://www.geoiptool.com/en/__ip_info/ it pinpoints my
    > _exact_ city of living, not the ISP's. It did not even ask me to
    > allow a geop ip javascript to run it present sit instantly.


    So you've reached your conclusion on a sample size of one?

    --
    Grant Edwards grant.b.edwards Yow! I'm encased in the
    at lining of a pure pork
    gmail.com sausage!!
     
    Grant Edwards, Jul 12, 2013
    #5
  6. On Sat, Jul 13, 2013 at 2:38 AM, Grant Edwards <> wrote:
    > On 2013-07-12, ?????????????? <> wrote:
    >> When visiting http://www.geoiptool.com/en/__ip_info/ it pinpoints my
    >> _exact_ city of living, not the ISP's. It did not even ask me to
    >> allow a geop ip javascript to run it present sit instantly.

    >
    > So you've reached your conclusion on a sample size of one?


    This is Nikos. He doesn't read responses properly, doesn't do his
    research, and has (by his own admission) an iron head that doesn't let
    information cross it lightly. Yes, he reached his conclusion on a
    sample size of one.

    Oh, and just for laughs, I tried a few of my recent mobile IP
    addresses in the GeoIP lookup. All of them quoted Melbourne someplace,
    some in the CBD and some out in the suburbs, but all vastly wrong, and
    places I haven't been. But I'd never expect it to be accurate on
    those.

    ChrisA
     
    Chris Angelico, Jul 12, 2013
    #6
  7. Îικόλας

    Ian Kelly Guest

    On Fri, Jul 12, 2013 at 10:32 AM, Íéêüëáò <> wrote:
    >
    > I know i have asked before but hwta i get is ISP city not visitors precise
    > city.
    >
    > GeoLiteCity.dat isnt accurate that's why it comes for free.
    > i must somehow get access to GeoIPCity.dat which is the full version.
    >
    > And of course it can be done, i dont want to believe that it cant.
    >
    > When visiting http://www.geoiptool.com/en/__ip_info/ it pinpoints my _exact_
    > city of living, not the ISP's.
    > It did not even ask me to allow a geop ip javascript to run it present sit
    > instantly.


    Try this:

    1) Go to http://incloak.com (or any other free web proxy site).
    2) Paste in the URL http://www.geoiptool.com and press Enter
    3) See where it thinks you are now.

    When I tried it, it placed me on the wrong side of the Atlantic Ocean.
     
    Ian Kelly, Jul 12, 2013
    #7
  8. Îικόλας

    Terry Reedy Guest

    On 7/12/2013 1:19 PM, Ian Kelly wrote:

    > Try this:
    >
    > 1) Go to http://incloak.com (or any other free web proxy site).
    > 2) Paste in the URL http://www.geoiptool.com and press Enter
    > 3) See where it thinks you are now.
    >
    > When I tried it, it placed me on the wrong side of the Atlantic Ocean.


    Me to. Thanks for the link.

    --
    Terry Jan Reedy
     
    Terry Reedy, Jul 12, 2013
    #8
  9. Îικόλας

    MRAB Guest

    On 12/07/2013 17:32, Îικόλας wrote:
    >
    > I know i have asked before but hwta i get is ISP city not visitors
    > precise city.
    >
    > GeoLiteCity.dat isnt accurate that's why it comes for free.
    > i must somehow get access to GeoIPCity.dat which is the full version.
    >
    > And of course it can be done, i dont want to believe that it cant.
    >
    > When visiting http://www.geoiptool.com/en/__ip_info/ it pinpoints my
    > _exact_ city of living, not the ISP's.


    Have you considered that your ISP might be in the same city as you?

    According to geoiptool, my ISP is near Leeds, UK, but the important
    point is that _I'm not_.

    > It did not even ask me to allow a geop ip javascript to run it present
    > sit instantly.
    >
    > So, it certainly is possible if only one can find the correct database
    > to use.
    >
    > So, my question now is, if there is some way we can get an accurate Geo
    > City database.
    >
     
    MRAB, Jul 12, 2013
    #9
  10. On 07/12/2013 10:32 AM, Îικόλας wrote:
    > So, my question now is, if there is some way we can get an accurate Geo
    > City database.


    As has been said pretty much by every other poster, there is no way to
    do get an accurate location database. Period.

    The databases that do exist were built by hand, and also guessed at
    based on routing information. The best you can really do is region, or
    country, and even that fails sometimes.

    If you want to know a visitor's city you should ask them using the new
    browser location apis available to javascript.

    http://diveintohtml5.info/geolocation.html

    Since IPs can be dynamic, sometimes even assigned across a region,
    there's no way to accurately map ip addresses to a city with the
    reliability that you seem to want. Google is pretty accurate because
    they've spent a lot of time building up their own database, and also
    convincing users to reveal their locations to them. Unless you do the
    same thing, you have to just get by with what others have provided for you.
     
    Michael Torrie, Jul 12, 2013
    #10
  11. On Sat, 13 Jul 2013 02:47:38 +1000, Chris Angelico <>
    declaimed the following:

    >
    >Oh, and just for laughs, I tried a few of my recent mobile IP
    >addresses in the GeoIP lookup. All of them quoted Melbourne someplace,
    >some in the CBD and some out in the suburbs, but all vastly wrong, and
    >places I haven't been. But I'd never expect it to be accurate on
    >those.
    >

    Well... the MaxMind demo of "my IP" did get the proper metropolitan
    area... But they list the ISP as "AT&T"... My real ISP is Earthlink
    (piggybacking on AT&T DSL service).

    The Lat/Long, however shows as

    42.9634 -85.6681
    whereas a recent GPS readout shows
    42.9159 -85.5541

    or 2m50s too far north, and 6m50s too far west.

    Same website, accessed from my Blackberry phone, gave a result of
    "United States, NA" and location 38 -97
    --
    Wulfraed Dennis Lee Bieber AF6VN
    HTTP://wlfraed.home.netcom.com/
     
    Dennis Lee Bieber, Jul 13, 2013
    #11
  12. On Fri, Jul 12, 2013 at 7:04 PM, Dennis Lee Bieber <>wrote:

    > On Sat, 13 Jul 2013 02:47:38 +1000, Chris Angelico <>
    > declaimed the following:
    >
    > >
    > >Oh, and just for laughs, I tried a few of my recent mobile IP
    > >addresses in the GeoIP lookup. All of them quoted Melbourne someplace,
    > >some in the CBD and some out in the suburbs, but all vastly wrong, and
    > >places I haven't been. But I'd never expect it to be accurate on
    > >those.
    > >

    > Well... the MaxMind demo of "my IP" did get the proper metropolitan
    > area... But they list the ISP as "AT&T"... My real ISP is Earthlink
    > (piggybacking on AT&T DSL service).
    >
    > The Lat/Long, however shows as
    >
    > 42.9634 -85.6681
    > whereas a recent GPS readout shows
    > 42.9159 -85.5541
    >
    > or 2m50s too far north, and 6m50s too far west.
    >
    > Same website, accessed from my Blackberry phone, gave a result of
    > "United States, NA" and location 38 -97
    > --
    > Wulfraed Dennis Lee Bieber AF6VN
    > HTTP://wlfraed.home.netcom.com/
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >


    Speaking more from a political perspective, an important aspect of the
    internet is that if you are a publisher who doesn't require registration to
    read what you post, your readers are free to be more or less anonymous.
    This is a good thing in many ways. If you have a service that requires
    some sort of sign up, then you can require knowing things about them
    (location, etc). If you want to know where your readers are, you need to
    make arrangements with their ISPs to get that information, since in many
    cases the ISP has a physical link to your machine. But why should they
    provide that to you? After all you are not their customer.

    It might be fun to know, but the repercussions are serious.


    --
    Joel Goldstick
    http://joelgoldstick.com
     
    Joel Goldstick, Jul 13, 2013
    #12
  13. On Sat, Jul 13, 2013 at 9:04 AM, Dennis Lee Bieber
    <> wrote:
    > On Sat, 13 Jul 2013 02:47:38 +1000, Chris Angelico <>
    > declaimed the following:
    >
    >>
    >>Oh, and just for laughs, I tried a few of my recent mobile IP
    >>addresses in the GeoIP lookup. All of them quoted Melbourne someplace,
    >>some in the CBD and some out in the suburbs, but all vastly wrong, and
    >>places I haven't been. But I'd never expect it to be accurate on
    >>those.
    >>

    > Well... the MaxMind demo of "my IP" did get the proper metropolitan
    > area... But they list the ISP as "AT&T"... My real ISP is Earthlink
    > (piggybacking on AT&T DSL service).
    >
    > The Lat/Long, however shows as
    >
    > 42.9634 -85.6681
    > whereas a recent GPS readout shows
    > 42.9159 -85.5541
    >
    > or 2m50s too far north, and 6m50s too far west.
    >
    > Same website, accessed from my Blackberry phone, gave a result of
    > "United States, NA" and location 38 -97


    When you try to place a visitor geographically by IP address, the only
    thing you can be absolutely 100% certain of is which RIR they're at
    (proxies aside - you're just testing the proxy rather than the
    ultimate origin). Country is also highly likely to be right, though
    not certain (I've never known it to be wrong, but I've never been able
    to confirm what happens with some of the small European countries -
    for all I know they could share ISPs and netblocks). Anything tighter
    than that is goign to be pretty hit-and-miss. But I have to say, it's
    improved a lot over the years. Back in the early 2000s - say, about 8
    years ago, I think - I was playing with this sort of technology, and
    it placed me in Sydney. That's one state away, lots of rivalry
    separating us (friendly rivalry, of course; in a country that's doing
    its best to kill us all, we can't afford to really hate each other),
    and roughly 750-1000km wrong by distance (depending on how you measure
    - most people don't put an odometer on a crow). So at least now it
    gets within the same degree of latitude and longitude... most of the
    time.

    ChrisA
     
    Chris Angelico, Jul 13, 2013
    #13
  14. On Sat, 13 Jul 2013 10:12:23 +0200, Lele Gaifax <>
    declaimed the following:

    >
    >Read the answers you got. What is *impossible* is *exactly and
    >precisely* find the geographical location of your machine, just using an
    >IP database like what you are doing, i.e. without your local machine
    >cooperating in the process (for example, by providing the numbers taken
    >from your local machine's GPS device).
    >

    Which obviously did NOT happen when I used my Blackberry phone -- which
    does have geolocation enabled (it is tagging photos with the city).

    The only thing MaxMind had available from my phone was apparently the
    DHCP server used by Blackberry, and gave out the approximate center of the
    US.
    --
    Wulfraed Dennis Lee Bieber AF6VN
    HTTP://wlfraed.home.netcom.com/
     
    Dennis Lee Bieber, Jul 13, 2013
    #14
  15. On Sat, 13 Jul 2013 08:32:24 +0300, ??????? <> declaimed
    the following:

    >???? 13/7/2013 1:07 ??, ?/? MRAB ??????:
    >>
    >> Have you considered that your ISP might be in the same city as you?
    >>
    >> According to geoiptool, my ISP is near Leeds, UK, but the important
    >> point is that _I'm not_.

    >
    >
    >My ISP is in Athens and i live in Thessaloníki and it returned back
    >Thessaloníki not Athens, which it was accurate for me.
    >

    Are you paying for a fixed IP number? I suspect you are if you were
    running a world-accessible server.

    Obviously a fixed IP will be tied to a fixed connection and thereby to
    a fixed location which can be provided to a location database.

    But most of us have DHCP assigned IP numbers, which change everytime we
    reboot our connection (or even when the DHCP lease expires -- which may be
    daily).

    The IP number I have today may be given to somebody else on the other
    side of the state tomorrow (though I suspect AT&T [phone company] keeps a
    block of IP numbers per city -- but even my connection, AT&T Grand Rapids,
    gets a "domain name" that identifies as Kalamazoo, when it gets to my ISP
    Earthlink).

    For DHCP, the only thing you can be sure of is that an IP database can
    identify the location of the DHCP server that issues the IP number. In a
    heavy population area, that may mean a DHCP server (and block of IP
    numbers) may be down to the suburb level. Out in the country, one server
    may handle multiple small towns.
    --
    Wulfraed Dennis Lee Bieber AF6VN
    HTTP://wlfraed.home.netcom.com/
     
    Dennis Lee Bieber, Jul 13, 2013
    #15
  16. Îικόλας

    Roy Smith Guest

    In article <krqqqt$eol$>,
    ÉΪÉ«É»όλας <> wrote:

    > But it works for me, How can it be impossible and worked for me at the
    > same time?
    >
    > Also i tried some other website that asked me to allow it to run a
    > javascript on my browser and it pinpointed even my street!
    >
    > If it wasnt possbile then MaxMind would be seeling its GeoIP2 app for
    > 1380$ per year.


    At Songza, we purchase the MaxMind database for doing geolocation based
    on IP address. This is how we enforce our content licenses which only
    allow us to stream music to the US and Canada. We also use it to target
    specific features (or advertising) to specific cities or other
    geographic areas within the US and Canada.

    That being said, we understand that it is only an approximate solution.
    It is useful, but not perfect. If you go to the MaxMind web site, you
    will see they have a range of products, at different prices, which
    promise various levels of accuracy and error rates. But none of them,
    for any amount of money, offers "resolution down to the street address
    and 0% error rate".
     
    Roy Smith, Jul 13, 2013
    #16
  17. On Sun, Jul 14, 2013 at 2:54 AM, Dennis Lee Bieber
    <> wrote:
    > Are you paying for a fixed IP number? I suspect you are if you were
    > running a world-accessible server.
    >
    > Obviously a fixed IP will be tied to a fixed connection and thereby to
    > a fixed location which can be provided to a location database.


    And even that is no guarantee. I have two connections, one static IP,
    the other dynamic. The static one fails geolocation by a greater
    distance than the other. No, there's no way to be sure.

    ChrisA
     
    Chris Angelico, Jul 13, 2013
    #17
  18. Îικόλας

    Roy Smith Guest

    In article <>,
    Dennis Lee Bieber <> wrote:

    > Obviously a fixed IP will be tied to a fixed connection and thereby to
    > a fixed location which can be provided to a location database.


    And even then, it can be wrong. When I worked for EMC, they
    (apparently, from what I could see) back-hauled internet connections for
    all their offices to Hopkinton, MA where they had one central ISP
    connection, via NAT. So, when I sat at my desk in White Plains, NY and
    went to Moviephone's web site, I was conveniently shown what all the
    theaters in the Hopkinton area were playing that day. Ditto for the
    weather.

    Not to mention that some IP addresses move. People use mobile devices
    in cars, busses, trains, planes, boats, etc. Not to mention somewhat
    more esoteric places like the ISS.
     
    Roy Smith, Jul 13, 2013
    #18
  19. Στις 13/7/2013 7:54 μμ, ο/η Dennis Lee Bieber έγÏαψε:
    > Are you paying for a fixed IP number? I suspect you are if you were
    > running a world-accessible server.
    >
    > Obviously a fixed IP will be tied to a fixed connection and thereby to
    > a fixed location which can be provided to a location database.
    >
    > But most of us have DHCP assigned IP numbers, which change everytime we
    > reboot our connection (or even when the DHCP lease expires -- which may be
    > daily).


    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?

    I

    --
    What is now proved was at first only imagined!
     
    Îικόλας, Jul 13, 2013
    #19
  20. On Sat, Jul 13, 2013 at 10:43 AM, Îικόλας <> wrote:
    > Στις 13/7/2013 7:54 μμ, ο/η Dennis Lee Bieber έγÏαψε:
    >>
    >> Are you paying for a fixed IP number? I suspect you are if you
    >> were
    >> running a world-accessible server.
    >>
    >> Obviously a fixed IP will be tied to a fixed connection and
    >> thereby to
    >> a fixed location which can be provided to a location database.
    >>
    >> But most of us have DHCP assigned IP numbers, which change
    >> everytime we
    >> reboot our connection (or even when the DHCP lease expires -- which may be
    >> daily).

    >
    >
    > 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?
    >


    It's not telling you where your ISP is headquartered. It's telling you
    where the servers that you're connecting to are. In your case, you're
    connecting to servers that your Athens-based ISP has in a Thessaloniki
    datacenter. The only way to get an accurate location is to use
    something other than IP- phones like to use a combination of their
    GPS, a map of the cell phone towers, and a map of wi-fi hotspots (this
    is one of the things that Google's StreetView cars log as they drive).
     
    Benjamin Kaplan, Jul 13, 2013
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. M West
    Replies:
    1
    Views:
    475
  2. news.skynet.be
    Replies:
    0
    Views:
    440
    news.skynet.be
    May 24, 2004
  3. Steven T. Hatton
    Replies:
    1
    Views:
    411
    Steven T. Hatton
    Dec 13, 2006
  4. SAL

    #Region #End Region issue

    SAL, Aug 29, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    359
    Alexey Smirnov
    Aug 29, 2008
  5. Bubu
    Replies:
    0
    Views:
    118
Loading...

Share This Page