#!/usr/bin/php "mac_address", "signal" => "signal_strength", "ssid" => "ssid" ); foreach( $m as $info ){ preg_match( "/( (\d+) - Address: (?P[:0-9A-Z]+)(.*)Signal level=(?P[-\d]+) dBm(.*)ESSID:\"(?P[^\"]+)\")+/s", $info, $ap ); $a = array(); foreach( $aLabels as $k => $l ){ if( is_array( $ap[$l] ) ) continue; $a[$l] = $ap[$k]; } if( $a["mac_address"] == "" ) continue; if( sizeof( $a ) > 0 ) $aAPs[] = $a; } // list of AP's MAC addresses from scan $loc = mac2loc( $aAPs ); echo "Google's location estimate:\n"; print_r( $loc ); echo "http://maps.google.co.uk/maps?q=".$loc->location->latitude.",".$loc->location->longitude."\n"; // submit each to google's lookup /* POST /loc/json HTTP/1.0 Host: www.google.com User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv; 1.9.2b4) Gecko/20091124 Firefox/3.6b4 Accept: text/html,aookication/xhtml+xml,application/xml;q=0.9,"/";q=0.6 Accept-Language: en-us,en;q=0.5 Accept-Encoding: none Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Content-Length: 127 Content-Type: text/plain; charset=UTF-8 Pragma: no-cache Cache-Control: no-cache {"version":"1.1.0","request_address":true,"wifi_towers":[{"mac_address":"$mac","ssid":"g","signal_strength":-72}]} */ function mac2loc( $aAPs ){ echo "Attempting to find location via Google location API\n"; if( sizeof( $aAPs ) > 0 ){ echo "Using the following nearby access points:\n"; foreach( $aAPs as $ap ){ echo $ap["ssid"].",".$ap["mac_address"].",".$ap["signal_strength"]."\n"; } }else{ echo "Couldn't find any nearby access points, trying location API anyway...\n"; } $ch = curl_init("http://www.google.com/loc/json"); $aPost = array(); $aPost["version"] = "1.1.0"; $aPost["request_address"] = true; $aPost["wifi_towers"] = $aAPs; $data = json_encode( $aPost ); // echo "Sending: ".$data."\n"; curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, $data ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); $rlt = curl_exec( $ch ); return json_decode( $rlt ); } // create "my maps" scatter of estimated locations // log results to twitter ?>