#!/usr/bin/perl use LWP::UserAgent; use JSON; my $browser = LWP::UserAgent->new; $browser->default_header('Pragma: no-cache'); $browser->default_header('Cache-control: no-cache'); my $location_req = HTTP::Request->new(POST => 'http://www.google.com/loc/json'); $location_req->content_type('application/x-www-form-urlencoded'); my $basic_request; $basic_request->{version} = '1.1.0'; $basic_request->{host} = 'maps.google.com'; $basic_request->{request_address} = 'true'; $basic_request->{address_language} = 'en_US'; my $wifi_towers; $wifi_towers->{mac_address} = 'ff-ff-ff-ff-ff-ff'; $wifi_towers->{signal_strength} = 8; $wifi_towers->{age} = 0; my $fake_request = $basic_request; $fake_request->{wifi_towers}->[0] = $wifi_towers; my $fake_request_json = encode_json($fake_request); $location_req->content($fake_request_json); my $fake_location_res = $browser->request($location_req); my $fake_location_data = decode_json($fake_location_res->content); my $real_request = $basic_request; $wifi_towers->{mac_address} = $ARGV[0]; $real_request->{wifi_towers}->[0] = $wifi_towers; my $real_request_json = encode_json($real_request); $location_req->content($real_request_json); my $real_location_res = $browser->request($location_req); my $real_location_data = decode_json($real_location_res->content); if (($fake_location_data->{location}->{latitude} == $real_location_data->{location}->{latitude}) && ($fake_location_data->{location}->{longitude} == $real_location_data->{location}->{longitude})){ print "The bogus request and real request have the same latiude and longitude ($fake_location_data->{location}->{latitude}, $fake_location_data->{location}->{longitude}). "; print "This usually means that there is no record for that MAC address. However it could mean that Google has a very accurate fix.\n"; }else{ print "Location for " . $wifi_towers->{mac_address} . "\n--------------------\n"; print "Latitude: " . $real_location_data->{location}->{latitude} . "\n"; print "Longitude: " . $real_location_data->{location}->{longitude} . "\n"; print "Address: " . $real_location_data->{location}->{address}->{street_number} . " " . $real_location_data->{location}->{address}->{street} . " " . $real_location_data->{location}->{address}->{city} . " " . $real_location_data->{location}->{address}->{region} . " " . $real_location_data->{location}->{address}->{postal_code} . "\n"; }