Skip to content

Instantly share code, notes, and snippets.

@pachacamac
Created June 30, 2011 17:34
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save pachacamac/1056734 to your computer and use it in GitHub Desktop.
Save pachacamac/1056734 to your computer and use it in GitHub Desktop.
Wanna know where you are?
#!/bin/bash
echo -n "{\"version\": \"1.1.0\",\"host\": \"maps.google.com\",\"request_address\": true,\"address_language\": \"en_GB\", \"wifi_towers\": [`iwlist scan 2> /dev/null | tr -d '\n' | sed -e 's/Cell [0-9]* - Address: \([0-9A-Z:]*\)[^C]*Channel:\([0-9]*\)[^S]*Signal level=\([0-9-]*\) dBm[^E]*E[^E]*ESSID:"\([^"]*\)"/\{"mac_address": "\1","signal_strength": \3,"age": 0,"channel": \2,"ssid": "\4"}/g' -e 's/[^{]*{/{/' -e 's/}[^{]*{/},{/g' -e 's/\}[^}]*$/\}/' `]}" | curl -s -X POST -d @/dev/fd/0 http://www.google.com/loc/json
# TIP: run with sudo for improved accuracy since iwlist can then provide more than the active hotspot
@dhruvasagar
Copy link

I get json parsing error.

@pachacamac
Copy link
Author

still works great for me... can you post the returned data?

@dhruvasagar
Copy link

Actually when I did sudo it worked great

@pachacamac
Copy link
Author

maybe on your system iwlist needs sudo rights to even give back the active access point. I'm on ubuntu ...

@dhruvasagar
Copy link

I am on ubuntu as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment