#!/usr/bin/perl use strict; use LWP; sub GetCode { my ($map_key,$lat,$long,$zoom)=@_; my $head = <Your current location HEAD my $body= < Your current location is $ENV{REMOTE_ADDR}:
BODY return($head,$body); } sub GetHTMLCode { my ($head,$body)=@_; my $html = < $head $body HTML return $html; } sub GetCoordinates { my $ip = shift; my ($lat,$long); my $ua = new LWP::UserAgent; $ua->agent("Opera/9.0 " . $ua->agent); $ua->timeout("5"); my $req = new HTTP::Request( GET => "http://www.geobytes.com/IpLocator.htm?GetLocation&template=php3.txt&IpAddress=$ip"); my $res = $ua->request($req); if (! $res->is_success) { die "can't get acccess to server \n"; } my $content=$res->content; foreach my $str (split(/\n/,$content)){ $lat = $1 if ($str =~ /meta name=.latitude. content=.(\d+\.\d+)./); $long = $1 if ($str =~ /meta name=.longitude. content=.(\d+\.\d+)./); } return($long,$lat); } my $map_key="ABQIAAAAMf5e3Tr70U_FwrRDDXe4_hSiRNrzZNSbufMINVC9pKrH0mnAyxQdcP_06DkIS2xwan7K2H122BlnlQ"; my $zoom="10"; my $ip_addr=$ENV{REMOTE_ADDR}; my ($long,$lat)=GetCoordinates($ip_addr); my ($head,$body)=GetCode($map_key,$lat,$long,$zoom); my $html = GetHTMLCode($head,$body); print "Content-type: text/html\n\n"; print $html;