473,802 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding geographic location of IP address

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
Aug 16 '07 #1
11 26305
Rik
On Thu, 16 Aug 2007 20:48:58 +0200, axlq <ax**@spamcop.n etwrote:
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:
<http://www.maxmind.com/app/geolitecity>
--
Rik Wasmus
Aug 16 '07 #2
NC
On Aug 16, 11:48 am, a...@spamcop.ne t (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

Aug 16 '07 #3
Rik
On Fri, 17 Aug 2007 00:02:59 +0200, NC <nc@iname.comwr ote:
>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
Aug 16 '07 #4
In article <op.tw51e6taqnv 3q9@metallium>,
Rik <lu************ @hotmail.comwro te:
>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
Aug 17 '07 #5
In article <op.tw6bb5g7qnv 3q9@metallium>,
Rik <lu************ @hotmail.comwro te:
[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
Aug 17 '07 #6
On Aug 16, 11:48 pm, a...@spamcop.ne t (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?
<snip>
1. http://ip-to-country.webhosting.info/
2. http://groups.google.com/group/comp....2732449830364d

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Aug 18 '07 #7
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_FORWARD ED_FOR'])
{
if (!$ip = $_SERVER['REMOTE_ADDR']){ $ip = ''; }
}
}
}
$this->clientIp = $ip;
$query =
file_get_conten ts("http://ws.arin.net/cgi-bin/whois.pl?queryi nput=$ip");
if (strstr($query, "No match")){ return; }
$this->name = $this->getSegment('Or gName:', $query);
if ($isp->isp == '')
{
$href = preg_match('/HREF="([^"]*)"/', $query, $uri);
$href = 'http://ws.arin.net' . $uri[1];
$query = file_get_conten ts($href);
}

$this->address = strtoupper($thi s->getSegment('Ad dress:' ,
$query));
$this->city = strtoupper($thi s->getSegment('Ci ty:' ,
$query));
$this->country = strtoupper($thi s->getSegment('Co untry:' ,
$query));
$this->email = strtolower($thi s->getSegment('Or gAbuseEmail:' ,
$query));
$this->name = strtoupper($thi s->getSegment('Or gName:' ,
$query));
$this->phone = strtoupper($thi s->getSegment('Or gAbusePhone:' ,
$query));
$this->state = strtoupper($thi s->getSegment('St ateProv:' ,
$query));
$this->zip = strtoupper($thi s->getSegment('Po stalCode:' ,
$query));
}

private function getSegment($seg ment, $source)
{
$pattern = '/' . $segment . '([^\n]*)\n/i';
$segment = preg_match($pat tern, $source, $matches);
$segment = preg_replace('/<[^>]*>/', '', $matches[1]);
return $segment;
}
}
?>
Aug 18 '07 #8
On Aug 19, 3:20 am, "Steve" <no....@example .comwrote:
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>
$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/

Aug 19 '07 #9
In article <Yg************ *@newsfe12.lga> , Steve <no****@example .comwrote:
>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
Aug 19 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6318
by: andreas.w.h.k. :-\) | last post by:
How do I change the address location in the wsdl <wsdl:port name="SearchSoap12" binding="tns:SearchSoap12"> <soap12:address location="http://searchservices/engine/search.asmx" /> </wsdl:port> Anderas
3
2274
by: Paul Aspinall | last post by:
Hi Does anyone know a Web service for IP address to Geographic location resolution? Thanks P.S. I am in the UK, but I assume any good web service would be worldwide??
2
11734
by: Paul Aspinall | last post by:
Hi Does anyone know a Web service for IP address to Geographic location resolution? Thanks P.S. I am in the UK, but I assume any good web service would be worldwide??
11
2143
by: -Lost | last post by:
IP2Location has limited databases: 0.0.0.0 to 99.255.255.255, which if I read correctly excludes: 100.255.255.255 through 255.255.255.255 MindMax is awesome! However, it only offers Country and City lookups. The problem with both of these however is a proprietary binary format (DAT), which excludes anyone from making specific changes, i.e. corrections.
1
1690
by: bennett | last post by:
Hi Has anyone ever tried to store international address information in to a single data example UK Address Nildram Ltd Ardenham Court Oxford Road
17
3791
by: abhimanyu.v | last post by:
Hi Guys, I have one doubt. The test program is given below. It uses two way of finding out the offset of a variable in structure. I executed the program and found the same result. My question is what is difference between 1) (unsigned long) &((struct foobar *)0)->foo and
1
1385
luvgis
by: luvgis | last post by:
Hi All, I am fairly new to Access and the forums but I would appreciate any insight into this question of mine... I am working with transportation data and I have a series of trips each with a unique trip idea. The trips all have a "Start_Place" and "End_Place" (the geographic location where the trip begins and a different location whree the trip ends). These is what I'm working with: TRIP_ID START_PLAC END_PLACE START_TIME ...
6
7123
by: Narasimha Rao | last post by:
Hi, I have IP Addresses in my DB table. I want to find the geographic location of each IP address. Can anyone help me if there is any API or solution for this. Thanks in advance.
275
12420
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10536
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9114
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.