During a course team meeting today, I idly mentioned that we should be able to run a simple browser based activity involving the geolocation of a student’s computer based on Google knowing the location of their wifi router. I was challenged about the possibility of this, so I did a quick bit of searching to see if there was an easy way of looking up the MAC addresses (BSSID) of wifi access points that were in range, but not connected to:
which turned up:
The airport command with '-s' or '-I' options is useful: /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport
(On Windows, the equivalent is maybe something like netsh wlan show network mode=bssid ??? And then call it via python.)
The second part of the jigsaw was to try to find a way of looking up a location from a wifi access point MAC address – it seems that the Google geolocation API does that out of the can:
An example of how to make a call is also provided, as long as you have an API key… So I got a key and gave it a go:
:-)
Looking at the structure of the example Google calls, you can enter several wifi MAC addresses, along with signal strength, and the API will presumably triangulate based on that information to give a more precise location.
The geolocation API also finds locations from cell tower IDs.
So back to the idea of a simple student activity to sniff out the MAC addresses of wifi routers their computer can see from the workplace or home, and then look up the location using the Google geolocation API and pop it on a map.
Which is actually the sort of thing your browser will do when you turn on geolocation services:
But maybe when you run the commands yourself, it feels a little bit more creepy?
PS sort of very loosely related, eg in terms of trying to map spaces from signals in the surrounding aether, a technique for trying to map the insides of a room based on it’s audio signature in response to a click of the fingers: http://www.r-bloggers.com/intro-to-sound-analysis-with-r/
PPS here’s a start to a Python script to grab the MAC addresses and do the geolocation calls
import sys print(sys.platform) #/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport import subprocess def getWifiMacAddresses(): #autodetect platform and then report based on this? results = subprocess.check_output(["/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport", "-s"]) #win? #results = subprocess.check_output(["netsh", "wlan", "show", "network"]) #linux? #! apt-get -y install wireless-tools #results = subprocess.check_output(["iwlist","scanning"]) results = results.decode("utf-8") # needed in python 3 ls = results.split("\n") ls = ls[1:] macAddr={} for l in [x.strip() for x in ls if x.strip()!='']: ll=l.split(' ') macAddr[l.strip().split(' ')[0]]=(l.strip().split(' ')[1], l.strip().split(' ')[2]) return macAddr #For Mac: postjson={'wifiAccessPoints':[]} hotspots=getWifiMacAddresses() for h in hotspots: addr,db=hotspots[h] postjson['wifiAccessPoints'].append({'macAddress':addr, 'signalStrength':int(db)}) url='https://www.googleapis.com/geolocation/v1/geolocate?key={}'.format(googleMapsAPIkey) import requests r = requests.post(url, json=postjson) r.json()
I seem to recall Google got prosecuted for “accidentally” recording all this info when they were doing the StreetView thing. Might have been in Germany?
Yep, that was “a thing” a few years ago, eg as described here: https://www.monash.edu/__data/assets/pdf_file/0011/141230/vol-39-3-burdon-and-mckillop.pdf
Did you try it with another MAC address? I have tried about 2 months ago and it always returns my GPS location, even if I requested another MAC address.
The API will respond with co-ordinates that relate to whatever you ask it to geocode…
Related – some wifi tools in Mac Wireless settings: http://www.computerworld.com/article/2476307/mac-os-x/mac-os-x-os-x-mavericks-using-apple-s-hidden-wi-fi-diagnostics-tool.html and http://www.macworld.com/article/1162117/monitor_wi_fi_with_lions_hidden_tool.html