4

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?

  • Maybe this can help: askubuntu.com/questions/142581/… – Parto Mar 6 '14 at 9:28
  • Do you have a GPS device attached on on your USB ports? – Radu Rădeanu Mar 6 '14 at 15:09
  • @AvatarParto that answer only talks about the library there is no command line app for it. – Mike McKay Mar 7 '14 at 6:19
  • @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): support.apple.com/kb/ht5403 – Mike McKay Mar 7 '14 at 6:20
  • @MikeMcKay Yah, that's why I wrote 'Maybe this can help'. It's like more info or something. – Parto Mar 7 '14 at 6:26
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
| improve this answer | |
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.

| improve this answer | |
  • python-geoclue not available in 18LTS. – Sqerstet Mar 5 at 4:00
  • @Sqerstet I think this answer is obsolete. I think it's based on geoclue v0.x – myrdd Jun 27 at 22:32
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'
| improve this answer | |
  • 1
    Any reason for -1? – Radu Rădeanu Mar 7 '14 at 14:05
  • 2
    guess he is asking about Mozilla's location service to lookup wireless access points and their known location – Waqas Mar 7 '14 at 14:08
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))
| improve this answer | |
-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\\'
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.