Skip to content

Instantly share code, notes, and snippets.

@73696e65
Last active February 20, 2019 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 73696e65/1630f1a4869630d6e4efd9fd637567e3 to your computer and use it in GitHub Desktop.
Save 73696e65/1630f1a4869630d6e4efd9fd637567e3 to your computer and use it in GitHub Desktop.
Google Wifi Geolocation (Mac OS X)
#!/usr/bin/env python
# Locates nearby access points for input to The Google Maps Geolocation API
# MAC OS X only
# Based on: https://github.com/localtracker/Google-Wifi-Geolocation-GNU-Linux
from os import popen
from sys import exit
from urllib2 import urlopen
from re import findall, compile
def process_data(data):
for line in data:
# Parse SSID, MAC, SIG
try:
x = findall(r'(.+) ([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}) (-?\d+)',
line.lstrip())[0]
except:
continue
print '[+] Adding: ', x
mac_ssid_list.append(x)
def geolocator():
print "\n[+] Generating URL:"
gl_url = 'https://maps.googleapis.com/maps/api/browserlocation/json?browser=firefox&sensor=true'
for (ssid, mac, sig) in mac_ssid_list:
gl_url += "&wifi=mac:%s%%7Cssid:%s%%7Css:%s" % (mac.replace(":", "-"), ssid.replace(" ", "%20"), sig)
print gl_url
# Reads the html response from server
api_response = urlopen(gl_url).read()
latitude = compile('"lat" : (.+),').findall(api_response)[0]
longitude = compile('"lng" : (.+)').findall(api_response)[0]
accuracy = compile('"accuracy" : (.+),').findall(api_response)[0]
print '\nYour Location (as per google maps api):'
print 'Latitude: ' + latitude
print 'Longitude: ' + longitude
print 'Accuracy: Within ' + accuracy + ' mts'
if __name__ == "__main__":
mac_ssid_list = []
output = popen("/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport scan")
# Pass the output and skip header
process_data(output.readlines()[1:])
geolocator()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment