(Ovid) Re: Getting longitude and latitude from an IP address
by Ovid (Cardinal) on Jan 05, 2002 at 05:47 UTC
|
Hey, fun script! Hope you don't mind, but I figured I would tighten it up a bit, add strict, and make it cross-platform compatible by using LWP::Simple.
#!/usr/bin/perl -w
use strict;
use LWP::Simple;
my @x =('192.172.226.77');
foreach my $ipaddress (@x)
{
my $url =
"http://netgeo.caida.org/perl/netgeo.cgi/netgeo.cgi?".
"method=getLatLong&target=$ipaddress&.cgifields=method&.cgifie
+lds=nonblocking";
my $result= get( $url );
my ( $lat, $long ) = ( $result=~ /LAT:\s+(-?\d+\.\d+).*LONG:\s+(-
+?\d+\.\d+)/s );
$lat += 180 if $lat < 0;
$long += 180 if $long < 0;
print "Address: $ipaddress\tLat: $lat\tLong: $long\n";
}
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats. | [reply] [d/l] |
A reply falls below the community's threshold of quality. You may see it by logging in. |
Re: Getting longitude and latitude from an IP address
by dws (Chancellor) on Jan 05, 2002 at 04:55 UTC
|
Given direct access to a GPS, you could optimize the lookup for 127.0.0.1.
Seriously, though, since a substantial chunk of the IP addresses one typically sees in a server log are dynamically allocated (e.g., via @home or pacbell.net), or are funnelled via NAT through a single IP address that may be far distant from the source, the latitude and longitude this produces should be considered to be "for amusement purposes only".
| [reply] |
|
|
I wholeheartedly agree, especially with such things as AOL's users all funnelling through Virginia. But, if I really want to know where someone was I'd try for other methods. As I said...it's a fairly simple page-parsing script, more of use as something for newbie perl people to scan than anything else.
Kickstart
| [reply] |
Re: Getting longitude and latitude from an IP address
by mojotoad (Monsignor) on Jan 05, 2002 at 22:58 UTC
|
There is an interesting article in the International Herald Tribune today that discusses the impending balkanization of the internet using tools such as your script (i.e., servers denying access based on geographical location).
I´m not convinced it will become as widespread as the author seems to believe, but it´s a good read.
Matt
Update: The original IHT article, from Jan 4, 2002, can now only be found on The Washington Post archives although it requires a pay-per-whack account for the full fetch. :-(
| [reply] |
|
|
I suspect it's already happening...I once wrote a script for a girlfriend who wrote an online journal that sent visitors to various pages depending on their IP address (well, the first two parts anyway - testing for ISP). This allowed her to send her parents and other relatives off to a page telling them to screw off! :)
The thing is...who knows? It's hard to tell how many people are doing this sort of thing. I suspect that I wouldn't mind terribly much if I went to (for example) eBay and all the prices were in Canadian dollars (since I'm in Vancouver). I might get a little annoyed if I went to Google and my searches came up only with Canadian sites though. It would remove the effectiveness of the service, rather than enhancing it.
Kickstart
| [reply] |
|
|
| [reply] |
|
|
Unless you're in Afghanistan, Iraq, or some other place like that... yup. There are still some restrictions but they are a little more relaxed now (to the best of my knowledge).
----
Zak
| [reply] |
Re: Getting longitude and latitude from an IP address
by blakem (Monsignor) on Jan 05, 2002 at 06:31 UTC
|
Why are you adding 180 to negative values? For one thing the sign on those numbers is important... for another, -10W does not equal 170E.... Whatever you were attempting to do, I think abs($long) would be better than $long+180.
-Blake
| [reply] [d/l] [select] |
Re: Getting longitude and latitude from an IP address
by elwarren (Priest) on Jan 10, 2002 at 01:25 UTC
|
I wish I could contribute more than, "that's cool!" but gosh darnit, it is cool. This should be put into a module and released on CPAN.
People have been putting lat/long info into dns records for awhile now, but it's never really caught on. I've been recently thinking about this since wireless usage has been growing.
Does anyone know how the pgp.mit.edu site does it's location verification? Does it actually do any? | [reply] |
Re: Getting longitude and latitude from an IP address
by Anonymous Monk on Jan 19, 2003 at 08:31 UTC
|
You know NetGeo has a a perl module available on thier site that will do all the work for you without having to parse thier page. The NetGeo API includes functions take arguments that are either ASN's, ip addr's, or hostnames. Some of the available functions are: getLatLon, getCountry, getRecord, etc. | [reply] |
Re: Getting longitude and latitude from an IP address
by Hacker1 (Initiate) on Dec 12, 2011 at 03:35 UTC
|
Hi All,
I tried the original version by Kickstart but got no output. Just "Lat: Long:" with no values.
I got no errors when running the code in the perl section of my webpage.
I used my Ip address as a test.
Any ideas?
Hacker1
| [reply] |
|
|
What makes you think IP addresses have a fixed location? And what makes you think the "location" of the IP address has any relation to the location of the user?
One of my former employers had a central and mandatory proxy at the headquarter, so each and every user accessing the internet appeared to be located at the headquarter, even if s(he) was several hundred km away.
At my current employer, I have to live with a partly broken proxy that I sometimes bypass using an SSH tunnel to a different computer. Whenever I do so, my "location" according to my current IP address jumps into a completely different state more than 30 km away, while I do not move a single millimeter.
Things become even more funny when you use a mobile computer with an UMTS or GPRS card.
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
| [reply] |
|
|
Hi. I have several notes
- Kickstart hasn't visited in 44 weeks, the post you replied to is 10 years old, and its real easy to miss a reply like yours
- AFAIK, the original by kickstart as posted is broken. (Ovid) Re: Getting longitude and latitude from an IP address would be worth trying...
- ... but the url in question has been gone for a long time, but even in 2002, there was a notice that this database was unmaintained/unreliable
- Like mentioned in Mapping visitors to my site, you should go with Geo::IP cpan Geo::IP
| [reply] [d/l] |