Skip to content

Instantly share code, notes, and snippets.

Created October 7, 2011 16:14
Show Gist options
  • Save anonymous/1270691 to your computer and use it in GitHub Desktop.
Save anonymous/1270691 to your computer and use it in GitHub Desktop.
simple script to run a triggered snmp command get to wifi client info
#!/bin/sh
place=".1.3.6.1.4.1.2021.255"
refresh() {
id=1
lastid=0
noise_reference=$(wl -i `nvram get wl0_ifname` noise | cut -d" " -f3)
for mac in $(wl -i `nvram get wl0_ifname` assoclist | cut -d" " -f2)
do
if test $lastid -eq 0
then
getnext_1361412021255="$place.3.54.1.3.32.1.1.1"
getnext_1361412021255354133211="$place.3.54.1.3.32.1.1.1"
getnext_1361412021255354133214="$place.3.54.1.3.32.1.4.1"
getnext_13614120212553541332113="$place.3.54.1.3.32.1.13.1"
getnext_13614120212553541332126="$place.3.54.1.3.32.1.26.1"
else
eval getnext_1361412021255354133211${lastid}="$place.3.54.1.3.32.1.1.$id"
eval getnext_1361412021255354133214${lastid}="$place.3.54.1.3.32.1.4.$id"
eval getnext_13614120212553541332113${lastid}="$place.3.54.1.3.32.1.13.$id"
eval getnext_13614120212553541332126${lastid}="$place.3.54.1.3.32.1.26.$id"
fi
rssi=$(wl -i `nvram get wl0_ifname` rssi $mac | cut -d" " -f3)
if test $rssi -eq 0
then
snr=0
else
let snr=-1*$noise_reference+$rssi
fi
mac=$(echo $mac | tr : ' ')
eval value_1361412021255354133211${id}=$id;
eval type_1361412021255354133211${id}='integer';
eval value_1361412021255354133214${id}='$mac';
eval type_1361412021255354133214${id}='octet';
eval value_13614120212553541332113${id}=$noise_reference;
eval type_13614120212553541332113${id}='integer';
eval value_13614120212553541332126${id}=$snr;
eval type_13614120212553541332126${id}='integer';
lastid=$id
let id=$id+1
done
if test $lastid -ne 0
then
eval getnext_1361412021255354133211${lastid}="$place.3.54.1.3.32.1.4.1"
eval getnext_1361412021255354133214${lastid}="$place.3.54.1.3.32.1.13.1"
eval getnext_13614120212553541332113${lastid}="$place.3.54.1.3.32.1.26.1"
eval getnext_13614120212553541332126${lastid}="NONE"
fi
}
LASTREFRESH=0
while read CMD
do
case "$CMD" in
PING)
echo PONG
continue
;;
getnext)
read REQ
let REFRESH=$(date +%s)-$LASTREFRESH
if test $REFRESH -gt 30
then
LASTREFRESH=$(date +%s)
refresh
fi
oid=$(echo $REQ | tr -d .)
eval ret=\$getnext_${oid}
if test "x$ret" = "xNONE"
then
echo NONE
continue
fi
;;
*)
read REQ
if test "x$REQ" = "x$place"
then
echo NONE
continue
else
ret=$REQ
fi
;;
esac
oid=$(echo $ret | tr -d .)
if eval test "x\$type_${oid}" != "x"
then
echo $ret
eval echo "\$type_${oid}"
eval echo "\$value_${oid}"
else
echo NONE
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment