8

It seems like there is a package called geoclue which uses Mozilla's location service to lookup wireless access points and their known location, but there doesn't seem to be a command line interface for this. Is there another way to do it? Any clever hacks?

Radu Rădeanu
  • 169,590
  • Maybe this can help: http://askubuntu.com/questions/142581/is-ubuntu-geoip-geoclue-used-for-tracking – Parto Mar 06 '14 at 09:28
  • Do you have a GPS device attached on on your USB ports? – Radu Rădeanu Mar 06 '14 at 15:09
  • @AvatarParto that answer only talks about the library there is no command line app for it. – Mike McKay Mar 07 '14 at 06:19
  • 1
    @RaduRădeanu I don't have a GPS device. I want to use the names of Wifi access points and a database of locations, like how OSX does it (and google also): http://support.apple.com/kb/ht5403 – Mike McKay Mar 07 '14 at 06:20
  • @MikeMcKay Yah, that's why I wrote 'Maybe this can help'. It's like more info or something. – Parto Mar 07 '14 at 06:26

5 Answers5

4

If you want IP based lookup... (but you'll have to fix the HTML formatting of the output)

wget http://cqcounter.com/whois/my_ip_address.php && egrep "IP Location|City|Latitude|Longitude" my_ip_address.php
philshem
  • 2,093
2

Here's my own best answer, which tries out all of the different geoclue providers available in 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

This results in:

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

Which is a big step forward, but it seems that all of the providers are using IP based lookup, and my VPN totally throws that off. Seems like there should be a provider that only uses wifi access points, but I haven't found it yet.

1

To get your location by IP you can use:

curl -s http://whatismycountry.com/ | sed -n 's|.*> *\(.*\)</h3>|\1|p'

To get your coordinates by IP you can use:

curl -s http://whatismycountry.com/ | sed -n 's/.*Coordinates \(.*\)<.*/\1/p'
Radu Rădeanu
  • 169,590
0

Here's a Python 2.x script similar to the one posted by @Mike McKay, which will use all the available Geoclue providers and output their location information in a pretty-printed format (requires apt-get install python-geoclue):

#!/usr/bin/env python

from __future__ import print_function
import Geoclue
from datetime import datetime

print("Geoclue version %s" % Geoclue.VERSION)

dl = Geoclue.DiscoverLocation()
dl.init()
providers = dl.get_available_providers()

for provider in providers:
  pname = provider['name']
  dl.set_position_provider(pname)
  position = dl.get_location_info()

  print("\n%s\n%s" % (pname, "-"*len(pname)))
  for k, v in position.items():
    if k.endswith('_timestamp'):
      v = datetime.fromtimestamp(v)
    print("%-25s%s" % (k+':',v))
Dan
  • 651
-1

There is a workaround that use your IP and find your location based to your Real IP.

first install lnyx

sudo apt-get install lynx-cur

Now the command is:

lynx -dump http://www.ip-adress.com/ip_tracer/?QRY=$1|grep address|egrep 'city|state|country'|awk '{print $3,$4,$5,$6,$7,$8}'|sed 's\ip address flag \\'|sed 's\My\\'
Maythux
  • 84,289