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.
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.
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:
Its asks for permission the first time, and then it works without any additional interaction. Also, the format
parameter is nice:
geolocate-cli is still in alpha but should do the job.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With