vy32
vy32

Reputation: 29677

Geolocating 802.11 access points by MAC address using Google Geolocation API

Support for the Google Geolocation API is now built in to most browsers. They do this, in part, by sending to Google the MAC address of nearby 802.11 access points (those whose beacons are captured by your computer.)

I have a large number of 802.11 packets captured from various locations. I'm looking to geolocate the 802.11 access points. Assume that we only have their mac addresses. This should be possible by using the Google Geolocation API.

Sources that I've found to date that might be helpful on this include:

The first is probably the best bet. Problem is, I'm not sure how to use the example there and actually create a program that lets me pipe in the MAC addresses and output lat/long pairs. I'm also not sure how to run JavaScript from a Unix/MacOS command line.

I know that this is a lot to ask, but does anybody have any clue where I should start?

Upvotes: 8

Views: 6939

Answers (1)

goat
goat

Reputation: 31834

<?php

$mac = $_SERVER['argv'][1];


$postData = '{
    "version": "1.1.0", 
    "wifi_towers": [{
        "mac_address": "' . $mac . '", 
        "ssid": "0", 
        "signal_strength":-72
    }]
}';

$opts = array(
  'http'=>array(
    'method' => "POST",
    'header'  => 'Content-type: application/x-www-form-urlencoded',
    'content' => $postData
  )
);


$response = file_get_contents(
    'http://www.google.com/loc/json', 
    false, 
    stream_context_create($opts)
);

$loc = json_decode($response, true);

echo $loc['location']['latitude'];
echo ',';
echo $loc['location']['longitude'];

Command line usage:

php geo.php "mac addy here"

Upvotes: 9

Related Questions