Finding geographic location of IP address
Finding geographic location of IP address
am 16.08.2007 20:48:58 von axlq
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
Re: Finding geographic location of IP address
am 16.08.2007 20:53:20 von luiheidsgoeroe
On Thu, 16 Aug 2007 20:48:58 +0200, axlq wrote:
> 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.
> 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:
--
Rik Wasmus
Re: Finding geographic location of IP address
am 17.08.2007 00:02:59 von nc
On Aug 16, 11:48 am, a...@spamcop.net (axlq) wrote:
>
> 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.
> 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
Re: Finding geographic location of IP address
am 17.08.2007 00:27:31 von luiheidsgoeroe
On Fri, 17 Aug 2007 00:02:59 +0200, NC wrote:
>> 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
Re: Finding geographic location of IP address
am 17.08.2007 02:04:08 von axlq
In article ,
Rik wrote:
>> 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:
>
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
Re: Finding geographic location of IP address
am 17.08.2007 02:08:12 von axlq
In article ,
Rik wrote:
[snip explanation of effort involved maintaining an IP country database]
Thanks. I didn't realize it was so involved.
>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
Re: Finding geographic location of IP address
am 18.08.2007 17:01:59 von ng4rrjanbiah
On Aug 16, 11:48 pm, a...@spamcop.net (axlq) wrote:
> 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?
1. http://ip-to-country.webhosting.info/
2. http://groups.google.com/group/comp.lang.php/msg/99273244983 0364d
--
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
Re: Finding geographic location of IP address
am 19.08.2007 00:20:56 von Steve
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?query input=$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;
}
}
?>
Re: Finding geographic location of IP address
am 19.08.2007 10:16:44 von ng4rrjanbiah
On Aug 19, 3:20 am, "Steve" wrote:
> 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.
> $href = 'http://ws.arin.net'. $uri[1];
ws.arin.net host won't return whois info for all IP blocks. See my
post above.
--
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
Re: Finding geographic location of IP address
am 19.08.2007 21:24:26 von axlq
In article , Steve wrote:
>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
Re: Finding geographic location of IP address
am 19.08.2007 22:33:52 von Steve
"R. Rajesh Jeba Anbiah" wrote in message
news:1187511404.111954.150590@x40g2000prg.googlegroups.com.. .
| On Aug 19, 3:20 am, "Steve" wrote:
| > 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.
|
| > $href = 'http://ws.arin.net'. $uri[1];
|
|
| ws.arin.net host won't return whois info for all IP blocks. See my
| post above.
i realize that, however there are others you can query. that's not a big
deal. what i've shown is a means to query arin.net. you can create an
interface class and implementors for each ns server. a master isp class
would simply create an instance of each ns server you'd like to query until
it gets a hit from one.
i believe, as far as your other post goes, that this would be exactly the
steps described in the last link you gave...1 through 6. your post was less
than useful imho since it only talks about doing it. i gave a class that
works with arin.net that is simple and easily modifiable to work with other
isps...you'd simply change the name of the class and the labels you'd need
to parse for that particular ns server in order to get the values.
Re: Finding geographic location of IP address
am 19.08.2007 22:40:16 von Steve
"axlq" wrote in message
news:faa5da$qs9$1@blue.rahul.net...
| In article , Steve
wrote:
| >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.
really? the job of a name server is to be queried. do you have info on the
'cut off' that 'most' ns servers use? i'm not saying a local db isn't a good
idea, however see that you've avoided anything in doing so. you may well be
able to pull out geo info from your db, but nothing's to say your local db
isn't out of sync with actual ns server data. there's a whole bunch of
background coordination you'd have to do in order to make sure you were in
sync. to me, that seems more impracticle than just going to the source...at
least until you justify your claim of 'cut off' and 'most'.
;^)
Re: Finding geographic location of IP address
am 19.08.2007 23:07:19 von gordonb.nigm2
>really? the job of a name server is to be queried. do you have info on the
A whois server is not a name server. It is possible that both are
hosted on the same machine, but they are not the same thing. I
would expect that a name server would have 100 - 1000 times the
queries that a whois server would.
>'cut off' that 'most' ns servers use?
Worry about the cutoff that whois servers use, if any.
Note that, at least on my system, whois queries come with a terms
of use that does not allow high-volume automated electronic queries
except for the purpose of registering or modifying registrations
of domains, which geolocation isn't.
>i'm not saying a local db isn't a good
>idea, however see that you've avoided anything in doing so. you may well be
>able to pull out geo info from your db, but nothing's to say your local db
>isn't out of sync with actual ns server data. there's a whole bunch of
>background coordination you'd have to do in order to make sure you were in
>sync. to me, that seems more impracticle than just going to the source...at
>least until you justify your claim of 'cut off' and 'most'.
I don't know how much traffic YOU intend putting on the whois
servers, especially if you might do more than one lookup on a given
user per session (especially if they don't do cookies). It seems
to me you could reduce that a lot by putting the data in a local
db, and only going to the outside servers if, say, the age of the
local data is more than, say, 7 days from when you last got it from
a whois server. The data really shouldn't change that fast.
You should also be aware of the possibility that your web site
becomes inoperable (or just way too slow) should the whois servers
go down or become unreachable.
Re: Finding geographic location of IP address
am 20.08.2007 03:10:58 von Jerry Stuckle
Steve wrote:
> "axlq" wrote in message
> news:faa5da$qs9$1@blue.rahul.net...
> | In article , Steve
> wrote:
> | >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.
>
> really? the job of a name server is to be queried. do you have info on the
> 'cut off' that 'most' ns servers use? i'm not saying a local db isn't a good
> idea, however see that you've avoided anything in doing so. you may well be
> able to pull out geo info from your db, but nothing's to say your local db
> isn't out of sync with actual ns server data. there's a whole bunch of
> background coordination you'd have to do in order to make sure you were in
> sync. to me, that seems more impracticle than just going to the source...at
> least until you justify your claim of 'cut off' and 'most'.
>
> ;^)
>
>
A nameserver is no the same as a whois server.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Finding geographic location of IP address
am 23.08.2007 10:31:48 von ng4rrjanbiah
On Aug 20, 1:33 am, "Steve" wrote:
> "R. Rajesh Jeba Anbiah" wrote in messagenews:1187511404.111954.150590@x40g2000prg.googlegroup s.com...
> | On Aug 19, 3:20 am, "Steve" wrote:
> | > 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.
> |
> | > $href = 'http://ws.arin.net'. $uri[1];
> |
> |
> | ws.arin.net host won't return whois info for all IP blocks. See my
> | post above.
>
> i realize that, however there are others you can query. that's not a big
> deal. what i've shown is a means to query arin.net. you can create an
> interface class and implementors for each ns server. a master isp class
> would simply create an instance of each ns server you'd like to query until
> it gets a hit from one.
>
> i believe, as far as your other post goes, that this would be exactly the
> steps described in the last link you gave...1 through 6. your post was less
> than useful imho since it only talks about doing it. i gave a class that
> works with arin.net that is simple and easily modifiable to work with other
> isps...you'd simply change the name of the class and the labels you'd need
> to parse for that particular ns server in order to get the values.
Web scraping method is not the right option for whois, as they might
remove the web interface anytime.
I think the right option is to use whois commandline utility or to
use RWhois protocol
cfcace0ece554ed6>
Any whois servers won't allow you to do many requests; if want to
query so many requests, better to get the bulk DB from them after some
agreements.
--
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
Re: Finding geographic location of IP address
am 23.08.2007 10:52:27 von tanuj96
Try http://freeipservices.com
On Aug 16, 11:48 am, a...@spamcop.net (axlq) wrote:
> 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
Re: Finding geographic location of IP address
am 23.08.2007 16:24:04 von Steve
"tanuj96" wrote in message
news:1187859147.172255.172010@j4g2000prf.googlegroups.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...