Showing posts with label GPS. Show all posts
Showing posts with label GPS. Show all posts

Tuesday, August 3, 2010

bash oneliner, get GPS location + street address

Hey there folks,

It's been quite some time since I last blogged, just been busy with $reallife. Today I'll show you how to an answer the eternal question of "Where am I" from the comfort of your bash shell

The following code only works if:
- You run it in a root shell (Ubuntu users do: "sudo -i" then paste it)
- You are connected via Wifi to some access point
- Your wireless adapter is called wlan0 (otherwise replace it with the correct name)
- You're using a Linux system or something similar (i.e. Windows won't really work here)

et voila


/bin/echo '{"version": "1.1.0","host": "maps.google.com","request_address": true,"address_language": "en_GB", "wifi_towers": [{"mac_address": "' $( iwlist wlan0 scan | grep Address | head -1 | awk '{print $5}' | sed -e 's/ //g' ) '","signal_strength": 8,"age": 0}]}' | sed -e 's/" /"/' -e 's/ "/"/g' > /tmp/post.$$ && curl -X POST -d @/tmp/post.$$ http://www.google.com/loc/json | sed -e 's/{/\n/g' -e 's/,/\n/g'


I didn't really spend much time cleaning it up, since I'm busy, so that's like the first thing that worked. If any of you guys can skip writing to the file, let me know and I'll update it

PS: If the returned information is wrong, or some kind of "unknown" .. Consider yourself lucky, very lucky! That means Google does not (yet?) know where your wifi AP is. For the rest of us .. tin-foil all the way