Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get my geolocation in bash [closed]

I am looking for a good geolocation api to use from bash. I want this call to return at the very minimum the name of the city I am in, and the state.

I imagine that there must be some site I can curl, or some scripting language that has a package that works. The machine does not have a GPS, but it does use wireless internet most of the time if that is needed.

like image 722
icco Avatar asked Mar 13 '10 00:03

icco


4 Answers

I was looking at this problem again recently and found whereami, a geolocation bash script for Mac OS X Snow Leopard, which takes advantage of Core Location. This will tend to be much more precise than IP geolocation, and it works well in my tests.

like image 154
npdoty Avatar answered Nov 17 '22 20:11

npdoty


Since whereami is not (officially) available for Swift 2 and Swift 3, I digged a bit deeper and found locateme what does its job on OSX 10.12.4:

Screenshot of LocateMe Its asks for permission the first time, and then it works without any additional interaction. Also, the format parameter is nice:

enter image description here

like image 25
Thomas Kekeisen Avatar answered Nov 17 '22 21:11

Thomas Kekeisen


geolocate-cli is still in alpha but should do the job.

like image 2
fmark Avatar answered Nov 17 '22 21:11

fmark


Scraping the first Google hit result for "geoip" seems to work easily enough.

$ curl http://www.maxmind.com/app/locate_my_ip |
> awk '/<table>/{RS=RS RS}/tblProduct1/'

I haven't checked their EULA to see if using their service this way is okay, but they do also provide GeoIP libraries for C, Perl, Python, etc. with a "lite" database that you can distribute (with conditions).

like image 1
ephemient Avatar answered Nov 17 '22 21:11

ephemient