开发者

How to get my geolocation in bash [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

开发者_如何学Python

Closed 4 years ago.

Improve this question

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:

How to get my geolocation in bash [closed]

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

How to get my geolocation in bash [closed]


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 your platform is a *nixlike that supports network-manager, you can use this script: curl "https://maps.googleapis.com/maps/api/browserlocation/json?browser=firefox&key=AIzaSyDBgL8fm9bD8RLShATOLI1xKmFcZ4ieMkM&sensor=true" --data-urlencode "`nmcli -f SSID,BSSID,SIGNAL dev wifi list |perl -ne "if(s/^(.+?)\s+(..:..:..:..:..:..)\s+(.+?)\s*$/&wifi=mac:\2|ssid:\1|ss:\3/g){print;}"`" Check out How to create a script to query Google Browserlocation for more details.

Notice that there's some limit to this service. It was working fine, at first, but now I get "status" : "OVER_QUERY_LIMIT". I don't know what the limit is because I can only seem to find geocoding references, but if anyone knows, please tell me!


Wireless internet meaning WiFi, CDMA2k, UMTS, EDGE... ? And your carrier? Not that it matters.

Really. I'd start investing in a GPS dongle.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜