Get Lat/Lon Geolocation using Bash (or Python) and your Wifi connection
In some cases, you may not have a GPS module available but will still want to find out your current location. We are able to do this using…
Get Lat/Lon Geolocation using Bash (or Python) and only a WiFi connection
In some cases, you may not have a GPS module available but will still want to find out your current location. We are able to do this using the Born Again SHell command curl
Photo by Alex Perez on Unsplash
The command
The command you are interested in is:
curl ipinfo.io
This produces an output like so:
"ip": "90.221.xx.xx",
"hostname": "xxxxxxxx.bb.xxx.com",
"city": "London",
"region": "England",
"country": "GB",
"loc": "51.3xxx,-0.1xxx",
"org": "AS5607 Sky UK Limited",
"postal": "EC1A",
"timezone": "Europe/London",
"readme": "https://ipinfo.io/missingauth"
Although this is not exactly correct, It gives a rough approximation of the location-based on internet routing — pretty neat considering we don't have a GPS locator on us.
Only selecting the location
If we only want the latitude and longitude of our location we can append loc to the previous command:
curl ipinfo.io/loc
This gives just LAT, LON as the output.
Getting location using WiFi from Python
To do this we can run a shell command from python and read the returned values as so:
import os
lat,lon = os.popen('curl ipinfo.io/loc').read().split(',')
Hope you found this useful, as now you can find yourself using only your internet connection.
메타데이터
- post_id
- 302ad41e9d93
- slug
- get-lat-lon-geolocation-using-bash-or-python-and-your-wifi-connection-302ad41e9d93
- url
- https://medium.com/cemac/get-lat-lon-geolocation-using-bash-or-python-and-your-wifi-connection-302ad41e9d93
- canonical_url
- https://medium.com/cemac/get-lat-lon-geolocation-using-bash-or-python-and-your-wifi-connection-302ad41e9d93
- author_url
- https://medium.com/@daniel-ellis
- status
- ok
- fetched_at
- 2026-06-09 21:21:26