Created
August 14, 2016 18:28
-
-
Save goran-mahovlic/3ff8e20f8fa26483e2f2aa881677cd96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
######################################################### | |
# Display the status of the Babel mesh. | |
# Latest version: | |
# http://redmine.bidon.ca/projects/reseaulibre-scripts/repository/raw/babelstatus.sh | |
# | |
# Usage: | |
# babelstatus.sh : shows babel routes | |
# babelstatus.sh --full : show other relevant info | |
# | |
# If you add your link-local addresses to your /etc/hosts | |
# you will get a more readable output. | |
######################################################### | |
# Detect the port used by Babel | |
# BABELDPORT=`uci get babeld.@general[0].local_server` | |
if [ "$BABELDPORT" = "" ]; then | |
BABELDPORT=33123 | |
fi | |
# Complicated awk script (because Perl is hard to install on OpenWRT) | |
AWK=' | |
function get_hostname_from_ip(ip) { | |
result = ip " [unknown]"; | |
command = "grep " ip " /etc/hosts"; | |
command | getline result; | |
close(command); | |
return result; | |
} | |
function get_neighbour(str) { | |
start = match(str, "via ([^ ]*)"); | |
ip = substr(str, start + 4, RLENGTH - 4); | |
host = get_hostname_from_ip(ip); | |
return host; | |
} | |
function strskip(str, skip) { | |
start = match(str, "(" skip ")"); | |
return substr(str, start + RLENGTH); | |
} | |
BEGIN { | |
neighstarted=0; | |
exportstarted=0; | |
} | |
{ | |
if (/^BABEL 0/) { | |
} | |
else if (/^add self alamakota id/) { | |
print "My MAC ID: ", $5; | |
} | |
else if (/^add neighbour/) { | |
if (! neighstarted) { | |
print "*** Neighbours ***"; | |
neighstarted=1; | |
} | |
ip = $5; | |
host = get_hostname_from_ip(ip); | |
print host strskip($0, "add neighbour [0-9a-zA-Z]+ address [^ ]+"); | |
} | |
} | |
nc :: $BABELDPORT | awk '{ if (/^add/) { print } }' | awk -v FULL=$1 "$AWK" | grep mesh0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment