> For the complete documentation index, see [llms.txt](https://sarpers-organization.gitbook.io/ctftricks/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sarpers-organization.gitbook.io/ctftricks/_chapter-intro-6/osint/information-gathering-osint-geolocation.md).

# Geolocation

## Geolocate Wifi Bssid (Wigle.net)

Use Wigle.net to find the geographical location and associated SSID of a known Wi-Fi BSSID. Navigate to the Wigle.net website and use their search functionality. Input the target BSSID (the MAC address of the access point) into the search bar. The site provides options for basic and advanced searches.

If the BSSID is present in Wigle.net's extensive database of mapped wireless networks, the site will display its approximate location on a map and the associated SSID.

For example, searching for the BSSID `A4:2B:8C:C5:E1:4B` on Wigle.net might reveal its location as London and the SSID as 'UnileverWiFi', demonstrating how previously collected war-driving data can pinpoint a network's physical location.

Beyond the web interface, Wigle also offers an API for programmatic access, allowing automated searching and integration of statistics. To use the API, you typically need to obtain API credentials (an API Name and Token) from your account page on the Wigle website. These credentials are used to authenticate your requests to the API endpoint, such as the search function.

A Python script can be used to query the Wigle API for network information based on a BSSID. Below is an example script that takes a BSSID as a command-line argument and searches the API:

```python
import requests
import json
import sys

# Usage: python wigleQuery.py <BSSID>

if len(sys.argv) != 2:
    print("Usage: python wigleQuery.py <BSSID>")
    sys.exit(1)

target_bssid = sys.argv[1]

# Replace with your actual API Name and Token from https://wigle.net/account
api_name = "YOUR_API_NAME"
api_token = "YOUR_API_TOKEN"

url = f"https://api.wigle.net/api/v2/network/search?onlymine=false&first=0&freenet=false&paynet=false&ssid=&lastupdt=&netid={target_bssid}&variance=&city=&postalcode=&state=&system=&country=&qos=&encryption=&auth=&actualq=&locale=&showNurfed=false&showOnlymine=false&showOnlyreg=false&resultsPerPage=100"

headers = {
    "Authorization": f"Basic {requests.auth._basic_auth_str(api_name, api_token)}"
}

response = requests.get(url, headers=headers)

if response.status_code == 200:
    data = response.json()
    if data["totalResults"] > 0:
        print(f"Found {data['totalResults']} results for BSSID {target_bssid}:")
        for network in data["results"]:
            print(f"  SSID: {network['ssid']}, Lat: {network['trilat']}, Lon: {network['trilong']}, Type: {network['netid'].split('-')[0]}")
    else:
        print(f"No results found for BSSID {target_bssid}.")
else:
    print(f"Error: {response.status_code}")
    print(response.text)
```

To use this script, save it as a `.py` file, replace `"YOUR_API_NAME"` and `"YOUR_API_TOKEN"` with your actual Wigle API credentials, and run it from your terminal, providing the target BSSID as an argument:

```bash
python wigleQuery.py A4:2B:8C:C5:E1:4B
```

The script will then query the Wigle API and print details like the SSID, latitude (`trilat`), and longitude (`trilong`) for any matching networks found in the database. This demonstrates how the API can be leveraged for automated lookups based on BSSID.
