1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Is there a way to use googles iptogeo somehow?

Discussion in 'General Programming Chat' started by SebastianJu, Jun 11, 2010.

  1. SebastianJu

    SebastianJu Power Member

    Joined:
    Mar 27, 2008
    Messages:
    679
    Likes Received:
    130
    Hello,

    google constantly is using a iptogeo database and I presume because google is big and long in the business their database is most correct.

    Is there a way to use googles ip to geo database? So that I can send a ip and get the country the ip is from?

    Thanks!
     
  2. albertb

    albertb Registered Member

    Joined:
    Nov 18, 2008
    Messages:
    53
    Likes Received:
    9
    You can send a GET request to google.com and google will return a 302 redirect to the country specific google site. You can figure out the country by parsing the TLD from the redirect location. The request must originate from the IP you want to resolve to a country so the code must run on the client side. This can probably be done with Javascript.

    If you want to get the country from the IP address using server side code, you should get a country to ip database and lookup the ip in the db. There are some free ones available. maxmind.c0m offers a free db as well as a subscription service.
     
    • Thanks Thanks x 1
  3. SebastianJu

    SebastianJu Power Member

    Joined:
    Mar 27, 2008
    Messages:
    679
    Likes Received:
    130
    Interesting idea to make a request on clients side. But when I think about I would have to send the client code that requests google and send it back to me. Then parse it and send out the real site. That probably can take a while. Would a website run javascript while the site is still loading?

    And I think there is the possibility that the browsersettings change the reached google.

    The free databases arent very exact I heard. But maybe there are quality differences so I can find a good one. But I think google would have the most exact one.

    But without the possibility to send google an ip directly you would need to go though your clients browser and I dont know if that works fast enough.
     
  4. grinding

    grinding Registered Member

    Joined:
    Oct 27, 2009
    Messages:
    62
    Likes Received:
    72
    Occupation:
    I'd rather be snorting cocaine off a hooker's ass
    Location:
    City of Angels
    • Thanks Thanks x 2
  5. albertb

    albertb Registered Member

    Joined:
    Nov 18, 2008
    Messages:
    53
    Likes Received:
    9
    The speed would depend on client's connection. But yeah, a javascript solution is not 100% reliable as the code must run on client side and the client could have JS disabled.
     
    Last edited: Jun 12, 2010
  6. SebastianJu

    SebastianJu Power Member

    Joined:
    Mar 27, 2008
    Messages:
    679
    Likes Received:
    130
  7. albertb

    albertb Registered Member

    Joined:
    Nov 18, 2008
    Messages:
    53
    Likes Received:
    9
    The client would need to have google gears installed for you to even use that thing.
     
  8. SebastianJu

    SebastianJu Power Member

    Joined:
    Mar 27, 2008
    Messages:
    679
    Likes Received:
    130
    Thats not good. Would have a very limited use...

    Im asking myself if maybe using more than one database would help. And the highest vote on a country would be chosen. But on the other hand... who knows if the minority is right with its vote?

    Till now im thinking about using different databases installed on the server + requests to onlinedatabases. These requests could maybe even done simultaneously letting the time decrease.

    And at the end use the country that have the most votes. But like I said maybe the most votes arent right.

    On the other hand... maybe the databases are exact enough. Detecting 1% of the countries wrong wouldnt result in a big drop in earnings...