from uuid import getnode
import re
import requests
class WigleAgent():
def __init__(self, username, password):
self.agent(username, password)
self.mac_address()
def get_lat_lng(self, mac_address=None):
if mac_address == None:
mac_address = self.mac_address
if '-' in mac_address:
mac_address = mac_address.replace('-', ':')
try:
self.query_response = self.send_query(mac_address)
response = self.parse_response()
except IndexError:
response = 'MAC location not known'
return response
def agent(self, username, password):
self.agent = requests.Session()
self.agent.post('https://wigle.net/api/v1/jsonLogin',
data={'credential_0': username,
'credential_1': password,
'destination': '/https://wigle.net/'})
def mac_address(self):
mac = hex(getnode())
mac_bytes = [mac[x:x+2] for x in xrange(0, len(mac), 2)]
self.mac_address = ':'.join(mac_bytes[1:6])
def send_query(self, mac_address):
response = self.agent.post(url='https://wigle.net/api/v1/jsonLocation',
data={'netid': mac_address,
'Query2': 'Query'})
return response.json()
def parse_response(self):
lat = self.get_lat()
lng = self.get_lng()
return lat, lng
def get_lat(self):
resp_lat = self.query_response['result'][0]['locationData'][0]['latitude']
return float(resp_lat)
def get_lng(self):
resp_lat = self.query_response['result'][0]['locationData'][0]['longitude']
return float(resp_lng)
if __name__ == "__main__":
wa = WigleAgent('jamiebull1', 'pZJTG7FMrn49YPzBCT')
print wa.get_lat_lng('00:1C:0E:42:79:43')
Diff to Previous Revision
--- revision 2 2013-08-12 13:45:16
+++ revision 3 2015-03-19 17:11:00
@@ -1,6 +1,8 @@
+from uuid import getnode
+import re
+
import requests
-import re
-from uuid import getnode
+
class WigleAgent():
@@ -22,10 +24,10 @@
def agent(self, username, password):
self.agent = requests.Session()
- self.agent.post('https://wigle.net//gps/gps/main/login',
+ self.agent.post('https://wigle.net/api/v1/jsonLogin',
data={'credential_0': username,
'credential_1': password,
- 'destination': '/gps/gps/main'})
+ 'destination': '/https://wigle.net/'})
def mac_address(self):
mac = hex(getnode())
@@ -33,10 +35,10 @@
self.mac_address = ':'.join(mac_bytes[1:6])
def send_query(self, mac_address):
- response = self.agent.post(url='https://wigle.net/gps/gps/main/confirmlocquery',
+ response = self.agent.post(url='https://wigle.net/api/v1/jsonLocation',
data={'netid': mac_address,
- 'Query': 'Query'})
- return response.text
+ 'Query2': 'Query'})
+ return response.json()
def parse_response(self):
lat = self.get_lat()
@@ -44,11 +46,13 @@
return lat, lng
def get_lat(self):
- resp_lat = re.findall(r'maplat=.*\&', self.query_response)
- lat = resp_lat[0].split('&')[0].split('=')[1]
- return float(lat)
+ resp_lat = self.query_response['result'][0]['locationData'][0]['latitude']
+ return float(resp_lat)
def get_lng(self):
- resp_lng = re.findall(r'maplon=.*\&', self.query_response)
- lng = resp_lng[0].split('&')[0].split('=')[1]
- return float(lng)
+ resp_lat = self.query_response['result'][0]['locationData'][0]['longitude']
+ return float(resp_lng)
+
+if __name__ == "__main__":
+ wa = WigleAgent('jamiebull1', 'pZJTG7FMrn49YPzBCT')
+ print wa.get_lat_lng('00:1C:0E:42:79:43')