I'm in a rural area, whereas you are most likely in a more metropolitan location.
$ curl ipinfo.io
{
"ip": "67.188.232.131",
"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": "67.188.232.131",
"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/8.8.8.8/org
AS15169 Google Inc.
More details available at http://ipinfo.io/developershttps://www.dailycred.com/api/info.json
This returns the current requester's location, device, and language settings. Or you can just look for location for a specific ip like so:
https://maps.google.com/maps?q=42.83330000000001,12.83330000...
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.
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)?
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.
Think about how much info google, apple, and others can collect with this, and build a database to sell.
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.
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 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
curl_close($ch);
$array = explode(',', $ip);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.
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;
$r->send_http_header("text/plain");
return OK if $r->header_only;
$r->print($r->remote_addr() . "\n");
return OK;
}1;
---
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...
It is built on Nginx + Lua so it has very minimal overhead.
Source code is on GitHub : https://github.com/fcambus/telize