似乎有一个名为geoclue的包,它使用Mozilla的位置服务来查找无线接入点及其已知位置,但似乎没有命令行接口。还有别的办法吗?有聪明的黑客吗?
发布于 2014-03-06 13:27:59
如果你想要基于IP的查找..。(但您必须修复输出的HTML格式)
wget http://cqcounter.com/whois/my_ip_address.php && egrep "IP Location|City|Latitude|Longitude" my_ip_address.php发布于 2014-03-07 06:34:38
这里是我自己最好的答案,它尝试了Ubuntu中所有不同的地理线索提供者:
apt-get install geoclue geoclue-ubuntu-geoip python-geoclue geoclue-yahoo geoclue-plazes geoclue-localnet geoclue-gypsy
echo "#!/usr/bin/env python
import Geoclue
providers = 'Gypsy, Hostip, Localnet, Plazes, Skyhook, Yahoo, Ubuntu GeoIP'
providers = providers.split(', ')
for provider in providers:
POS_PROVIDER = provider
location = Geoclue.DiscoverLocation()
location.init()
location.set_position_provider(POS_PROVIDER)
position = location.get_location_info()
print provider
print position['latitude']
print position['longitude']
" > location.py
python location.py这导致:
Gypsy
0.0
0.0
Hostip
39.8121
-76.9837
Localnet
39.8121
-76.9837
org.freedesktop.DBus.GLib.UnmappedError.GeoclueErrorQuark.Code1: Could not understand reply from server
Plazes
39.8121
-76.9837
org.freedesktop.DBus.GLib.UnmappedError.GeoclueErrorQuark.Code1: Couldn't parse response from web service
Skyhook
39.8121
-76.9837
Yahoo
39.8121
-76.9837
Ubuntu GeoIP
40.6501
-73.9496这是向前迈出的一大步,但似乎所有的提供商都在使用基于IP的查找,而我的VPN完全放弃了这一点。似乎应该有一个供应商,只使用无线接入点,但我还没有找到它。
发布于 2014-03-07 13:57:30
要通过IP获取您的位置,您可以使用:
curl -s http://whatismycountry.com/ | sed -n 's|.*> *\(.*\)</h3>|\1|p'要通过IP获取您的坐标,您可以使用:
curl -s http://whatismycountry.com/ | sed -n 's/.*Coordinates \(.*\)<.*/\1/p'https://askubuntu.com/questions/430218
复制相似问题