Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I find a location such as city/state or country from an ip address?

Is there a ruby gem or python module to do this? Or if there is a website which has an API.

share|improve this question

You can go here...Any such service is only a rough estimate for ANY IP address, but this is what you are looking for. (just enter the "IP Address to locate" and hit submit)

share|improve this answer
I have a long list of ip addresses so I was hoping I would be able to do it through a script – ed1t Jun 18 '11 at 18:45

If you want to see a geolocation from a website you are navigating easily, you should install Flagfox add-on for Firefox: you will se a flag near address bar and clicking, on it, more information (city, IP...).

Also, you can use to see the same detais for any IP address or server name.

share|improve this answer is an open-source project with the goal to build/maintain a database mapping IP addresses to cities. Their about page explains the data sources relied on to populate this database.

Using HostIP, there are two ways to get location data from an IP address:

They also have a well-designed and easy-to-use RESTFUL API: just pass in your ip address after the ip= in the GET request string):

import urllib

response = urllib.urlopen('').read()


Second, the Project Website also makes its complete database available for download.

share|improve this answer

You could use the API for this:

$ curl
  "ip": "",
  "hostname": "",
  "city": "Mountain View",
  "region": "California",
  "country": "US",
  "loc": "37.3860,-122.0838",
  "org": "AS15169 Google Inc.",
  "postal": "94040"

If you're only interested in one field you can add that to the URL to get it as plain text:

$ curl

$ curl

If you're looking for a python module is a simple wrapper, or is more fully featured and has built in support for and other providers.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.