Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • Geolocation source code from Mozilla 1.9.1 code base
  • MDN article on Monitoring WiFi access points
  • MDN article on using geolocation
  • Mozilla WebDev article on using Geolocation in the Browser

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?

like image 340
vy32 Avatar asked Jan 10 '11 03:01

vy32


People also ask

What is the Geolocation API with the Geolocation API you can obtain?

The Geolocation API is a very simple API that allows to get a device's current location coordinates. It has only two methods: getCurrentPosition and watchPosition and the data returned is very straightforward, but when coupled with a mapping API, complex location-aware web apps can be created.

Is Google Geolocation API free?

The Geolocation API uses a pay-as-you-go pricing model.

How do I get Google Maps API location?

To get current location using HTML5 Geolocation with Google Maps, you need to set an API key for Google Static Maps API. Go to https://console.developers.google.com and get a free API key for Google Map. Add this key to the code to work Geolocation with it.


1 Answers

<?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"
like image 189
goat Avatar answered Nov 07 '22 14:11

goat