Hacker News new | comments | show | ask | jobs | submit login
Show HN: IP Lookup (iplook.herokuapp.com)
72 points by hipaulshi 1251 days ago | hide | past | web | 47 comments | favorite

If you're after IP details via an API you should check out http://ipinfo.io, eg:

    $ curl ipinfo.io
      "ip": "",
      "hostname": "c-67-188-232-131.hsd1.ca.comcast.net",
      "city": "Mountain View",
      "region": "California",
      "country": "US",
      "loc": "37.385999999999996,-122.0838",
      "org": "AS7922 Comcast Cable Communications, Inc.",
      "phone": 650

    $ curl ipinfo.io/geo
      "ip": "",
      "city": "Mountain View",
      "region": "California",
      "country": "US",
      "loc": "37.385999999999996,-122.0838",
      "phone": 650

    $ curl ipinfo.io/org
    AS7922 Comcast Cable Communications, Inc.
    $ curl ipinfo.io/
    AS15169 Google Inc.
More details available at http://ipinfo.io/developers

We offer something similar for free. (One of our client deployments needed it, so we just made it free for everyone.)


This returns the current requester's location, device, and language settings. Or you can just look for location for a specific ip like so:


Interesting. Do you know how the Accept Language header is calculated? I can imagine that it can also be used to track users as in [1]

1: https://panopticlick.eff.org/

It's in each browser request as a header - we just echo it back because it's not available to js.


It picked out a beautiful location for me. I really wish I were there, but I'm in an office park much further north, in Padova, which the one in the story actual nailed down to a few meters.


By the way, Italy is amazingly beautiful isn't it! You can pretty much randomly pick a street view and without too much effort, find some interesting or beautiful scenery.

For those who can't be bothered digging, uses http://ip-api.com/json/

For those who don't want their web service to rely on other web services, I recommend MaxMind's lite database, they have a fairly recent downloadable binary of IP to geographic coodinates.

I've been using http://freegeoip.net/

It's not perfect, but it seems to be good enough for my purposes.

     $ip = $_SERVER['REMOTE_ADDR'];
     $ua = $_SERVER['HTTP_USER_AGENT'];
        $ch = curl_init();
        // set url
        curl_setopt($ch, CURLOPT_URL, "freegeoip.net/csv/"    . $ip);
        //return the transfer as a string
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        // $output contains the output string
        $ip = curl_exec($ch);
        // close curl resource to free up system resources
     $array = explode(',', $ip);

Author of freegeoip.net here. It uses the db from MaxMind. Worth mentioning that the system is not only free but also open source, available at github.com/fiorix/freegeoip (currently written in Go)

A while back I needed a no-cruft way to get my IP reliably, so put this in my nginx config, to allow "curl example.com/ip":

http {

    # ...

    perl_modules /etc/nginx/perl;

    perl_require myip.pm;

    # ...

    server {

    # ...

      location = /ip {

          perl myip::handler;


    # ...


then in /etc/nginx/perl/myip.pm :


package myip;

use nginx;

sub handler {

  my $r = shift;


  return OK if $r->header_only;

  $r->print($r->remote_addr() . "\n");

  return OK;



Honestly, I have been around the block trying to find a decent company that provides either a database or api for looking up a location from an ip address.

It seems like every company from MaxMind to IP2Location and all of the others are accurate for some ip addresses, and severely inaccurate for others. And I think that will only become more and more common as all of the ipv4 addresses run out and there are hundreds to thousands behind the same ip address.

I've even tried crowdsourcing from four different ip to location sources and even then, sometimes all four return different cities and even states for a single ip address.

Is there any company out there that is actually fairly accurate (on a city basis)?

I am guessing this is why companies like Google have sourced their own info.

Geo-locating by IP will always be an imperfect process because it's not actually geolocating the IP, it's geolocating the block owner.

My downtown Toronto office geo-locates as Kansas City in some cases because the org who owns the block is there. And I assume they are not keeping their records up to date as we have a /8 and I think they should be registering a sub-block or whatever it's called..

But there you go.

I would think geolocation would only get better as more people go mobile and their IP address (wifi or 3G) gets pinned to gps coordinates using location aware apps.

Think about how much info google, apple, and others can collect with this, and build a database to sell.

Yeah but those IPs are dynamic and change over time.. Unless the mobile providers (who are often national) restrict IPs to regions, you could have an IP be in one part of the country one week and in another part of the country the next, no?

You have a /8? Are you Xerox? General Electric? :)

There aren't that many /8s. You could just go through them all and see which one is "in Kansas City".

HP has two /8s... No idea what they're doing with >33 million IP addresses....

Sorry, I reasoned that wrong, I meant a /24.. :-(

Didn't mean to start a whole thing..

I recently noticed that you could create your own "IP -> countrycode" lookup system by using the delegation tables provided by arin/ripencc/afrinic/...

It might not be very accurate, but it's a fun little exercise: http://blog.marc-seeger.de/2013/09/07/ip-to-countrycode-with...

What about those of us that get easily excited over IPv6?

Is anyone collecting this info for ipv6? Netflix has me in the wrong continent...

For a fast GeoIP JSON API, you can try Telize which is open source and has a public API : http://www.telize.com

It is built on Nginx + Lua so it has very minimal overhead.

Source code is on GitHub : https://github.com/fcambus/telize

Are you subscribed to map box? It's fast no doubt, but why you didn't move to free alternatives to reduce cost?

you are absolutely right. switched to google map

In general, the accuracy of geolocation is at 70-80% at the city level. We have researched and compare the data from several providers such as IP2Location, Maxmind, Geobytes and so on. The IP address can be freely reallocated to any postcodes within one or multiple cities so we think that the 70-80% is acceptable.

Also available at http://viewdns.info/iplocation/. There's an API as well http://viewdns.info/api/.

What is the database behind all these geo IP providers? I see many APIs providing same functionality and results are the same. Is this database purchased from somewhere every time you want to do this?

Maxmind, probably. (http://www.maxmind.com/)

Simple and cool! I'm starting to learn python so I'll definitely be looking through the source, thanks for posting, flask looks like a nice little framework to get started on

If you want to take IP lookup one step further: https://github.com/fourtonfish/HelloSalut

Lol! Optus still calls its AS Microplex! Microplex hasn't been around in a decade and a half!

Maybe include information if the IP is an active Tor exit node?

Where can i find a copy of the database that is driving this?

Maxmind, http://dev.maxmind.com/geoip/geoip2/geolite2/, is one option. Look into their git-repo for clients to read into their proprietary (but effective) db-format.

Mine was accurate to within a half-mile, scary!

Mine is only 100m away - but then again, that's the location of the old GPO, which is usually used as the local "distance from X" position. I'm not sure about elsewhere, but here in Aus, ['road'] distance from A to B is the distance from A's post office to B's post office.

Mine was about 12 miles away from my actual location. It depends on your ISP, as well as your location.

I'm in a rural area, whereas you are most likely in a more metropolitan location.

This only returns the city name along with the latLng for it. You probably live close to the center of the city (or downtown)

Mine was out by 200 miles. But I suspect that is more down to our companies crazy network routing.

Is this on Github?

It literally says "fork me on GitHub" at the top right.

>It literally says "fork me on GitHub" at the top right.

It din't show up for me either. After a bit of investigating, it looks like Ghostery (and maybe AdBlock Plus too) sees Github ribbon as a tracker and automatically hides it.

Quite ironic given the nature of the page you were looking at, and the details that, presumably, DID show.

Way off topic (and probably annoying), but I literally see/hear the word 'literally' used in these two situations. When what is being said...

   1. Is obviously literal and does not need to be qualified.
   2. Isn't actually literal at all.
Literally, that's the only two ways I hear it (except for rare exceptions).

It's obviously being used here for emphasis and humour - totally valid.

Creepily cool!

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact