Welcome, guest | Sign In | My Account | Store | Cart

EDIT: WiGLE have retired this API and moved to api/v2

There is now a Python wrapper for the API which you can install using pip install pygle.

Python, 58 lines
 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
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_lng = self.query_response['result'][0]['locationData'][0]['longitude']
        return float(resp_lng)

if __name__ == "__main__":
    wa = WigleAgent('your-username', 'your-key')
    print wa.get_lat_lng('00:1C:0E:42:79:43')

This can be used in conjunction with something like scapy to find the location of the system on which the code is running, for example for a lost laptop. It can then send a message home so that it can be tracked down.

19 comments

Paolo Di Rollo 9 years, 1 month ago  # | flag

Hi, I try to use this class with my userid and my password. The code is the follow:\n

 from wigle_query import WigleAgent
 wa=WigleAgent('*******','*****');
 print wa.get_lat_lng('00:1C:0E:42:79:43');

but I have this response from Wigle https://gist.githubusercontent.com/paolodirollo/0ea91370651914522966/raw/b56fe3410fabde0f08101398e9d0f583796fc235/response What kind of error it is? How can I solve? Thank you in andvance

Jamie Bull (author) 9 years, 1 month ago  # | flag

Hi Paolo, The API seems to have changed to a much nicer one which returns JSON. I'm just testing a new version of this recipe and will update once it's working.

Jamie Bull (author) 9 years, 1 month ago  # | flag

Updated now.

Paolo Di Rollo 9 years, 1 month ago  # | flag

Thank you very much, I have been looking for some solution the last two days. Can you kindly send me a link to the documentation? the only resource that I found is this: http://www5.musatcha.com/musatcha/computers/wigleapi.htm and it is updated to 2005.

Jamie Bull (author) 9 years, 1 month ago  # | flag

I've not seen any documentation. I just sent a request manually, looked at the request headers in Chrome Developer tools network tab, and went from there. Feel free to fork and extend this recipe though if you'd like to make more of the API accessible.

Paolo Di Rollo 9 years, 1 month ago  # | flag

Hi Jamie, ok. There is only a little error on line 53, you should substitute "resp_lat" with "resp_lng"

Jamie Bull (author) 9 years, 1 month ago  # | flag

Thanks. Fixed now.

Dilan omed Mahmood 9 years ago  # | flag

Hi , is there any way to work on asp.net ? because i tried python dose not worked with me!

Jamie Bull (author) 9 years ago  # | flag

I don't see why not. It's just consuming an API.

Dilan omed Mahmood 9 years ago  # | flag

Jamie Bull, the problem is i want to try my query which is try to find free Wifi on the wigle.net but the problem is dose not allow me to do that :( is there any recommendation from you ? thanks

Dilan omed Mahmood 9 years ago  # | flag

i tried this code on python but error will popup here Traceback (most recent call last): File "python", line 59 print wi.get_lat_lng('00:1C:0E:42:79:43') ^ SyntaxError: invalid syntax

Dilan omed Mahmood 9 years ago  # | flag

i tried this code on python but error will popup here:\n Traceback (most recent call last):\n File "python", line 59\n print wi.get_lat_lng('00:1C:0E:42:79:43')\n ^\n SyntaxError: invalid syntax

alex 8 years, 10 months ago  # | flag

Heads up API change. could you update? ```

>>> import wigle
>> >w = wigle.Wigle('******','******')
>> >w.search(ssid="foobar")
      Traceback (most recent call last):
       File "<stdin>", line 1, in <module>
 File "/usr/local/lib/python2.7/dist-packages/wigle-0.0.4-py2.7.egg/wigle/__init__.py", line 153, in search
    data = resp.json()
TypeError: 'dict' object is not callable
```

also hand jammed to make sure i wasn't being dumb. URL: https://wigle.net/api/v1/jsonSearch?netid=00:22:55:DF:C8:01

output:

{"resultCount":1,"results":[{"qos":"0","trilong":"-87.60340118","wep":"N","transid":"20101228-00171","channel":"11","visible":"Y","lasttime":"2010-12-28 23:03:19","trilat":"41.89127731","freenet":"?","bcninterval":null,"lastupdt":"20101228230351","paynet":"Y","name":null,"userfound":false,"type":"infra","comment":null,"firsttime":"2010-12-28 18:21:52","discoverer":"bobzilla","netid":"00:22:55:df:c8:01","flags":null,"ssid":"Navypier"}],"last":1,"first":1,"success":true}

Jamie Bull (author) 8 years, 10 months ago  # | flag

@alex - I don't really have the time right now. Feel free to fork it though.

mike 8 years, 2 months ago  # | flag

(Sorry, for digging an old thread)

This works great, but very quickly I get the message { "success":false,"message":"too many queries" }

It only takes few requests to get blocked. And it takes several hours for it to work again.

Is there any trick or workaround for this problem? It would be greatly appreciated

Jamie Bull (author) 8 years, 2 months ago  # | flag

Sorry, I've not used this for a long time so no idea what the limits are. You'll probably need to use a proxy list though if it's rate limiting by IP.

Jamie Bull (author) 8 years, 2 months ago  # | flag

If it's username/key based limiting (probably more likely) then you might have more difficulty.

Justin Seto 7 years, 8 months ago  # | flag

I tried Changing the query from Mac to SSID but I keep receiving the error MAC Location unknown, any hints?

Jamie Bull (author) 7 years, 8 months ago  # | flag

Afraid not. I've not used this for a long time.