Forked from 73696e65/geolocation-googleapi-mac-os-x.py
Created
February 20, 2019 10:18
-
-
Save maurice-schuppe/0790f527f03b3bb423c16442e3302f28 to your computer and use it in GitHub Desktop.
Google Wifi Geolocation (Mac OS X)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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