How To Find IP Location?

How to find location of an IP Address Without using APIs?

  • More of a theoretical question. Yes, I know those types of questions are frowned upon here. But suppose APIs like MaxMind GeoIP's didn't exist, and you wanted to build a service that translated IP addresses to the city it's in. What would you do? How would you go about solving that problem?

  • Answer:

    Use the whois database to find out who the IP is allocated to. Use DNS to do a reverse lookup on the IP address. Use traceroute to guess the location based on the routers leading up to the host As an example, lets look at stackoverflow.com (64.34.119.12) $ whois 64.34.119.12 | egrep "(OrgName)|(City)|(State)|(Country)" OrgName: Peer 1 Network Inc. City: New York StateProv: NY Country: US whois shows us that they're probably in NY, NY. $ host 64.34.119.12 12.119.34.64.in-addr.arpa domain name pointer stackoverflow.com. Reverse DNS (PTR record) doesn't help here. However, a lot of ISPs do have region specific reverse DNS entries that can help with this process (especially for dynamically assigned hosts). As an example: $ host 24.25.195.1 1.195.25.24.in-addr.arpa domain name pointer sndgca-dns-cac-01.san.rr.com. This host is obviously identified and located by it's PTR record: a Time Warner (Road Runner) caching DNS server in San Diego, CA. Now, back to the stackoverflow.com locating process: $ traceroute stackoverflow.com traceroute to stackoverflow.com (64.34.119.12), 64 hops max, 40 byte packets ms (... removed the first few hops ...) 8 ae-6-6.ebr1.Chicago1.Level3.net (4.69.140.189) 30.9 ms 28.855 ms 25.183 ms 9 ae-2-2.ebr2.NewYork2.Level3.net (4.69.132.66) 54.373 ms 54.197 ms 48.171 ms 10 ae-6-6.ebr2.NewYork1.Level3.net (4.69.141.21) 48.250 ms 50.712 ms 51.293 ms 11 ae-62-62.csw1.NewYork1.Level3.net (4.69.148.34) 59.493 ms ae-82-82.csw3.NewYork1.Level3.net (4.69.148.42) 51.694 ms ae-62-62.csw1.NewYork1.Level3.net (4.69.148.34) 58.315 ms 12 ae-3-89.edge1.NewYork1.Level3.net (4.68.16.142) 51.529 ms ae-2-79.edge1.NewYork1.Level3.net (4.68.16.78) 50.77 ms ae-3-89.edge1.NewYork1.Level3.net (4.68.16.142) 50.567 ms 13 10ge-te-1-1.nyc-75bre-dis-2.peer1.net (216.187.115.77) 50.776 ms 51.193 ms 56.166 ms 14 gig2-0.nyc-gsr-b.peer1.net (216.187.123.5) 54.994 ms 58.813 ms 51.794 ms 15 gwny01.stackoverflow.com (64.34.41.58) 54.121 ms 52.65 ms 54.166 ms 16 * * * (... remaining time outs removed ...) The traceroute output confirms our suspicion that stackoverflow.com is hosted in NY, NY. That's one way to tackle geolocation without an API.

Henley Chiu at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

Im really guessing here but this may work. IP ranges are assigned by http://www.iana.org to regional providers. There are five of them. In turn each regional provider assign IP ranges to end users and internet service provides. If you can get/buy the information from the regional providers and their ISP clients you are in business.

Pablo Castellazzi

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.