# Geo geraten aus Nachbar WIFI Accesspoints - Beispielscript

**URL:** <https://forum.freifunk.net/t/geo-geraten-aus-nachbar-wifi-accesspoints-beispielscript/11164>\
**Category:** Technik\
**Created:** [6. März 2016 um 15:50 UTC](https://forum.freifunk.net/t/geo-geraten-aus-nachbar-wifi-accesspoints-beispielscript/11164 "2016-03-06T15:50:27Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![fuzzle](https://forum.freifunk.net/user_avatar/forum.freifunk.net/fuzzle/32/5599_2.png) [@fuzzle](https://forum.freifunk.net/u/fuzzle)\
**Post date:** [6. März 2016 um 15:50 UTC](https://forum.freifunk.net/t/geo-geraten-aus-nachbar-wifi-accesspoints-beispielscript/11164/1 "2016-03-06T15:50:28Z")

</div>

wollte das schon lange mal schreiben, ist fern von Perfekt.  
Skript zum herausfinden des Groben Standortes Anhand benachbarter WIFI Accesspoints

(funktioniert mit busybox wget so auch nicht auf den Routern selbt, u.a. wegen fehlender https unterstützung, dies hier muss also mit ssh zugang auf einen Knoten benutzt werden. desweiteren benutzt es ALLE gefundenen Nodes und benutzt NICHT die Empfangsstärke)

[start [Wiki]](https://cccfr.de/wiki/freifunk:verueckte_ideen_und_unbeantwortete_fragen#geo_ueber_nachbarnodes_checkeln) (eventuelle Nacharbeiten NUR dort!)

```auto
#!/bin/bash
#
# simple code to get geo out of mix of macs

if [$# != 1]; then
echo "usage of geoguess: $0 <node_ip>"
exit 1
fi

# debuglevel
debug=false

# get key out of keyfile
apikey=$(cat geoapikey)
# if there is no API Keyfile use test instead (limited!)
: ${apikey:=test}

# first get some macs from node, and ignore hostkeychecking
macs=$(ssh -lroot $1 -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "iwinfo phy0 scan |grep -o -E [0-9A-F]{2}[:][0-9A-F]{2}[:][0-9A-F]{2}[:][0-9A-F]{2}[:][0-9A-F]{2}[:][0-9A-F]{2}")

# make nice POST-string snippet out of it
string=$(echo -n $(for mac in $macs; do echo -n "{\"macAddress\": \"$mac\"},"; done))
string=$(echo ${string%?})

# make POST Wget request to mozilla 
# https://mozilla.github.io/ichnaea/api/geolocate.html
# basicly something like:
# wget -O geodata https://location.services.mozilla.com/v1/geolocate?key=test --post-data='{ "wifiAccessPoints": [{"macAddress": "00:00:11:22:33:44"},{"macAddress": "00:00:55:66:77:88"}]}' 
wget -q -O geodata https://location.services.mozilla.com/v1/geolocate?key=$apikey --post-data="{ \"wifiAccessPoints\": [$(echo -n $string)]}"

# sample output is something like
# {"location": {"lat": 48.0006632, "lng": 7.8236051}, "accuracy": 960.0275115}
# cat geodata
lat=$(cat geodata |grep -o [4-5][0-9].[0-9]* |head -n1)
lon=$(cat geodata |grep -o " [5-9].[0-9]*" |grep -o "[6-9].[0-9]*" |head -n1)
echo "you may try http://www.openstreetmap.org/?mlat=$lat&mlon=$lon#map=16/$lat/$lon&layers=N"
echo "or use this on router:"
echo "ssh -lroot $1 \"uci set gluon-node-info.@location[0].latitude=$lat ; uci set gluon-node-info.@location[0].longitude=$lon; uci set gluon-node-info.@location[0].altitude=200; uci set gluon-node-info.@location[0].share_location=1 ; uci commit gluon-node-info\""

if [$debug = true]; then
        echo "#### debugfoo"
        echo "request is : wget -q -O geodata https://location.services.mozilla.com/v1/geolocate?key=$apikey --post-data=\"{ \\\"wifiAccessPoints\\\": [$(echo -n $string)]}\""
        echo "api key is : $apikey"
        echo "macs is : $macs"
        echo "string becomes : $string"
        echo "return is : $(cat geodata)"
fi

```

---

_[View the full topic](https://forum.freifunk.net/t/geo-geraten-aus-nachbar-wifi-accesspoints-beispielscript/11164)._
