Skip to content

Instantly share code, notes, and snippets.

@TobleMiner
Last active January 2, 2019 19:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TobleMiner/182376850f849f3a6c6c7a5a718f3adc to your computer and use it in GitHub Desktop.
Save TobleMiner/182376850f849f3a6c6c7a5a718f3adc to your computer and use it in GitHub Desktop.
Simple script to analyze the transglobal table of batman
#!/usr/bin/env bash
node_mac_paths=('.nodes[].nodeinfo.network.mac')
batctl_count_hops() {
batctl -m "$1" tg |
sed 's/([[:space:]]*[0-9]\+)//g' | # Remove tq field
sed 's/[[:space:]]\+/ /g' | # Replace duplicate whitespace characters by a single space
cut -d' ' -f5 | # Extract nexthop
egrep -o '([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}' | # Match mac addresses only
sort | uniq -c | sort -k1nr | # Count number of devices using a certain nexthop
sed 's/[[:space:]]\+/ /g'
}
tgstats="`batctl_count_hops bat-ffki`"
nodes="`curl https://hopglass.freifunk.in-kiel.de/nodes.json 2> /dev/null`"
while read line; do
mac="$(echo "$line" | cut -d' ' -f2)"
name="$(echo "$nodes" | jq ".nodes | map(select(.nodeinfo.network | .. | strings | contains(\""$mac"\")))[].nodeinfo.hostname")"
echo "$line $name"
done <<< "$tgstats"
@rubo77
Copy link

rubo77 commented Jan 2, 2019

Das Script zeigt, wenn es auf einer node in Kiel ausgeführt wird, die Anzahl der Einträge in der transglobal table pro Node und löst direkt den dazugehörigen Knotennamen auf

Wann braucht man dies?

@TobleMiner
Copy link
Author

Das Skript erlaubt das einfache Finden von Knoten mit ungewöhnlich vielen Clients bzw. Einträgen in der Transglobal table. Das hilft beim Finden von falsch konfigurierten Knoten, welche bspw. mesh auf client netz bridgen

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