-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquery_google_loc.py
More file actions
71 lines (54 loc) · 1.51 KB
/
query_google_loc.py
File metadata and controls
71 lines (54 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python
"""
Copyright (C) 2010 Kees Cook <kees@outflux.net>
License: GPLv3
Find location of a MAC address via Google Location Services
http://code.google.com/p/gears/wiki/GeolocationAPI
Note: Google also uses your IP address to determine location, and if your IP
doesn't match up to where the MAC addresses are, they may return a location
of your city.
"""
import urllib2
from sys import argv
import json
def request_loc(bssid):
loc_req = {
'version': '1.1.0',
'request_address': True,
'address_language': 'en',
'wifi_towers': []
}
for b in bssid:
loc_req['wifi_towers'].append({
'mac_address': b.replace(':', '-'),
'signal_strength': 1
})
data = json.dumps(loc_req)
return urllib2.urlopen('https://www.google.com/loc/json', data).read()
def print_loc(*bssid):
loc_json = json.loads(request_loc(bssid))
print bssid,
try:
print ("%(city)s, %(country)s" % loc_json['location']['address']),
print "(%sm)" % loc_json['location']['accuracy']
except KeyError, e:
pass
print loc_json['location']
if loc_json['location']['accuracy'] >= 15000:
print "# Accuracy of 15km or higher seems to indicate unknown location..."
print ""
def main():
if len(argv) == 1:
# test mode
nets = ['00:88:88:88:00:2A', '00:88:88:88:00:2B']
elif argv[1].lower() == '--triangulate':
# display data using all of the mac addresses at once.
print "Using triangulate mode."
print_loc(*argv[2:])
return
else:
nets = argv[1:]
for line in nets:
print_loc(line)
if __name__ == "__main__":
main()