Finding geographic location of IP address 
August 16th, 2007, 07:55 PM
| | | |
Does anyone have a favored way of finding the geographic location
of a user's IP address, so that a php script can include content
relevant to that location?
Reverse-lookup of the hostname isn't reliable and often doesn't
work, especially if the returned hostname ends with .com, .net,
..info, .biz or other tld that doesn't reveal geographic location.
I also see a bunch of commercial services that offer a "country
whois" function for a subscription fee. You'd think this sort of
capability would be standardized by now.
Is anybody doing this? If so, how?
-A | 
August 16th, 2007, 07:55 PM
| | | | re: Finding geographic location of IP address
On Thu, 16 Aug 2007 20:48:58 +0200, axlq <axlq@spamcop.netwrote: Quote:
Does anyone have a favored way of finding the geographic location
of a user's IP address, so that a php script can include content
relevant to that location?
>
Reverse-lookup of the hostname isn't reliable and often doesn't
work, especially if the returned hostname ends with .com, .net,
.info, .biz or other tld that doesn't reveal geographic location.
>
I also see a bunch of commercial services that offer a "country
whois" function for a subscription fee. You'd think this sort of
capability would be standardized by now.
| Hardly. Giving out IP's has little to do with location. It's pretty hard
work keeping it up to date. There's hardly any chance of something really
reliable, and certainly not for free. Quote: |
Is anybody doing this? If so, how?
| By using a database updated by a third party, with information more or
less accurate most of the time:
<http://www.maxmind.com/app/geolitecity>
--
Rik Wasmus | 
August 16th, 2007, 11:05 PM
| | | | re: Finding geographic location of IP address
On Aug 16, 11:48 am, a...@spamcop.net (axlq) wrote: Quote:
>
Does anyone have a favored way of finding the geographic location
of a user's IP address, so that a php script can include content
relevant to that location?
| Nope. IP addresses often lie. AOL users in the U.S. all appear to
come from Virginia. AOL users in Germany are often seen as coming
from the UK. Users on corporate networks are usually seen as located
at the corporation's headquarters or even the corporation's telco's
headquarters. Quote:
I also see a bunch of commercial services that offer a "country
whois" function for a subscription fee. You'd think this sort of
capability would be standardized by now.
| It is. Matching IP addresses with locations is done based on WHOIS
information. But to get and keep current WHOIS for the entire
Internet, you need to be a domain registrar or good friends with
one. :) Plus, WHOIS reflects who owns the IP address, not who uses
it...
Cheers,
NC | 
August 16th, 2007, 11:35 PM
| | | | re: Finding geographic location of IP address
On Fri, 17 Aug 2007 00:02:59 +0200, NC <nc@iname.comwrote: Quote: Quote:
>I also see a bunch of commercial services that offer a "country
>whois" function for a subscription fee. You'd think this sort of
>capability would be standardized by now.
| >
It is. Matching IP addresses with locations is done based on WHOIS
information.
| They might use them, however, mathing IP-adresses to country (state, city)
is not entirely done by WHOIS information. It is often a fallback if
nothing else is known/certain. A lot of the more reliable sources
continuously hold massive 'surveys' (do you live here? if not, please tell
us where you do...), and get information from third parties where an
IP-address and geolocation are given (some ISP's and larger online stores
for example, allthough they would have to have a very precise privacy
statement IMHO). Millions of datasets get processed to extrapolate some
probable range of ip's for a location, in which case the whois information
comes in handy for determening which ISP's hold certain ranges. That's
more of a 'boundary'-determining of a range then the actual 'value' of a
range. AOL is certainly hard to pin down due to their proxy network.
It's all quite a lot of work, and terribly expensive.
And on a sidenote in this thread a warning to all trying to use
geolocation to determine language: don't, use the language-accept headers.
Geolocation might be usefull to provide 'local' information or to
determine the general location of (groups of) clients.
--
Rik Wasmus | 
August 17th, 2007, 01:05 AM
| | | | re: Finding geographic location of IP address
In article <op.tw51e6taqnv3q9@metallium>,
Rik <luiheidsgoeroe@hotmail.comwrote: Quote: Quote: |
>Is anybody doing this? If so, how?
| >
>By using a database updated by a third party, with information more or
>less accurate most of the time:
><http://www.maxmind.com/app/geolitecity>
| Thanks. Gag... scan through a 28 megabyte database just to find my
user's city? All I need are countries, and I see that site has a
country databse. Thanks.
-A | 
August 17th, 2007, 01:15 AM
| | | | re: Finding geographic location of IP address
In article <op.tw6bb5g7qnv3q9@metallium>,
Rik <luiheidsgoeroe@hotmail.comwrote:
[snip explanation of effort involved maintaining an IP country database]
Thanks. I didn't realize it was so involved. Quote:
>And on a sidenote in this thread a warning to all trying to use
>geolocation to determine language: don't, use the language-accept
>headers. Geolocation might be usefull to provide 'local'
>information or to determine the general location of (groups of)
>clients.
| All I need it for is to make an educated guess about the user's
country, just so a selection box will default to the right type of
currency for exchange-rate calculations. Geolocation isn't even
necessary for the site I'm building but I thought it would be a
user-friendly touch to have certain defaults based on country.
-A | 
August 18th, 2007, 11:25 PM
| | | | re: Finding geographic location of IP address
here's a straight-forward method to begin with. any other issues raised can
be answered easily with a little investigation and modification to this
general approach. the best you can do is find the issuing isp. most of the
time, the user of the ip is very near the issuer.
hih,
me
==================
<?
class isp
{
public $address = '';
public $city = '';
public $clientIp = '';
public $country = '';
public $email = '';
public $name = '';
public $phone = '';
public $state = '';
public $zip = '';
private function __clone(){}
public function __construct($ip = '')
{
if (!$ip)
{
if (!$ip = $_SERVER['HTTP_CLIENT_IP'])
{
if (!$ip = $_SERVER['HTTP_X_FORWARDED_FOR'])
{
if (!$ip = $_SERVER['REMOTE_ADDR']){ $ip = ''; }
}
}
}
$this->clientIp = $ip;
$query =
file_get_contents("http://ws.arin.net/cgi-bin/whois.pl?queryinput=$ip");
if (strstr($query, "No match")){ return; }
$this->name = $this->getSegment('OrgName:', $query);
if ($isp->isp == '')
{
$href = preg_match('/HREF="([^"]*)"/', $query, $uri);
$href = 'http://ws.arin.net' . $uri[1];
$query = file_get_contents($href);
}
$this->address = strtoupper($this->getSegment('Address:' ,
$query));
$this->city = strtoupper($this->getSegment('City:' ,
$query));
$this->country = strtoupper($this->getSegment('Country:' ,
$query));
$this->email = strtolower($this->getSegment('OrgAbuseEmail:' ,
$query));
$this->name = strtoupper($this->getSegment('OrgName:' ,
$query));
$this->phone = strtoupper($this->getSegment('OrgAbusePhone:' ,
$query));
$this->state = strtoupper($this->getSegment('StateProv:' ,
$query));
$this->zip = strtoupper($this->getSegment('PostalCode:' ,
$query));
}
private function getSegment($segment, $source)
{
$pattern = '/' . $segment . '([^\n]*)\n/i';
$segment = preg_match($pattern, $source, $matches);
$segment = preg_replace('/<[^>]*>/', '', $matches[1]);
return $segment;
}
}
?> | 
August 19th, 2007, 09:25 AM
| | | | re: Finding geographic location of IP address
On Aug 19, 3:20 am, "Steve" <no....@example.comwrote: Quote:
here's a straight-forward method to begin with. any other issues raised can
be answered easily with a little investigation and modification to this
general approach. the best you can do is find the issuing isp. most of the
time, the user of the ip is very near the issuer.
| <snip> Quote: |
$href = 'http://ws.arin.net'. $uri[1];
| <snip>
ws.arin.net host won't return whois info for all IP blocks. See my
post above.
--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/ | 
August 19th, 2007, 08:25 PM
| | | | re: Finding geographic location of IP address
In article <YgKxi.41$b23.10@newsfe12.lga>, Steve <no.one@example.comwrote: Quote:
>here's a straight-forward method to begin with. any other issues raised can
>be answered easily with a little investigation and modification to this
>general approach. the best you can do is find the issuing isp. most of the
>time, the user of the ip is very near the issuer.
| [snip example to get country information from whois server like ARIN]
That's an interesting approach, but seems impractical to me. Most
whois servers will cut you off if you have too many requests in one
day. For a high-traffic site that needs geolocation information, a
local database may be best.
-A | 
August 23rd, 2007, 09:55 AM
| | | | re: Finding geographic location of IP address
Try http://freeipservices.com
On Aug 16, 11:48 am, a...@spamcop.net (axlq) wrote: Quote:
Does anyone have a favored way of finding the geographic location
of a user'sIPaddress, so that a php script can include content
relevant to that location?
>
Reverse-lookup of the hostname isn't reliable and often doesn't
work, especially if the returned hostname ends with .com, .net,
.info, .biz or other tld that doesn't reveal geographic location.
>
I also see a bunch of commercial services that offer a "country
whois" function for a subscription fee. You'd think this sort of
capability would be standardized by now.
>
Is anybody doing this? If so, how?
>
-A
| | 
August 23rd, 2007, 03:25 PM
| | | | re: Finding geographic location of IP address
"tanuj96" <tanujchatterjee@gmail.comwrote in message
news:1187859147.172255.172010@j4g2000prf.googlegro ups.com...
| Try http://freeipservices.com
except it's a completely bad sign when they use my ip and show i'm from san
fransisco when i'm more than half way across a continent.
ip-address.com got it correct. there are tons of others. again, you could
use them instead of a whois. the parsing code i wrote would do fine to get
data from the mirad out there. worried about copious calls to it? get a list
of those you want to use and select from them randomly. if one doesn't turn
up geo info (changed the tags the info is in, didn't have any info, etc.)
move to the next. it would be far easier to notice that a site's tags have
changed than trying to keep up a db with current information...unless you
want to pay, which i'm not to into doing.
of course others have different thoughts on all of that. i'll go with
whatever my employer wants, but if it's just for me...parsing/scraping is
the lightweight, free approach that only requires you to monitor the tags on
the page(s) you're scraping...and you can have your system notify you when
it appears successive requests are turning up blanks...hell, before you get
your panties in a wad, you can even turn around automatically and test those
with a known ip (yours) and if it's blank, email or otherwise alert yourself
to get things back in line with that page's tags.
but i digress... |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|