#!/bin/sh for F in $* do echo echo '###################' $F '###################' # Asking the unit for info_data.js gives a line that looks like # DATA="blahblah" curl -s -u admin:admin --connect-timeout 10 http://${F}/info_data.js | perl -e ' sub charToSixBits { return index(".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_", $_[0]); } # Get the DATA="blah" line, which must be exactly 551 bytes long if (read(STDIN,$X,1000) != 551) { exit 1; } $X=substr $X,6,-1; # Leave the actual data # Convert string $X (base64) to $S (binary) $S=""; while ($X) { $cc = (charToSixBits(substr($X,0,1)) << 18) + (charToSixBits(substr($X,1,1)) << 12) + (charToSixBits(substr($X,2,1)) << 6) + (charToSixBits(substr($X,3,1))); $S = $S . chr(($cc >> 16) & 255) . chr(($cc >> 8) & 255) . chr($cc & 255); $X=substr($X,4); } # Unpack the various fields from the first 72 bytes of the block ($SSID, $channel, $BSSID, $txrate, $quality, $MACbridged, $MAC, $IP, $firmware) = unpack("x2 A32 c1 A6 c1 c1 H12 H12 N a11", $S); # Print them out... printf("%12s: %s\n", "SSID", $SSID); printf("%12s: %s\n", "channel", $channel); printf("%12s: %d (%s Mbit/s)\n", "txrate", $txrate, ($txrate <= 1) ? "1" : ($txrate <= 3) ? "2" : ($txrate <= 7) ? "5.5" : "11"); printf("%12s: %d\n", "quality", int(0.5 + ((100 * $quality) / 92))); printf("%12s: %s\n", "MAC bridged", $MACbridged); printf("%12s: %s\n", "MAC", $MAC); printf("%12s: %d.%d.%d.%d\n", "IP", 255 & ($IP >> 24), 255 & ($IP >> 16), 255 & ($IP >> 8), 255 & $IP, ); printf("%12s: %d.%d.%d.%d%d%d.%d%d%d\n", "firmware", ord(substr($firmware,0,1)), ord(substr($firmware,1,1)), ord(substr($firmware,2,1)), ord(substr($firmware,3,1)), ord(substr($firmware,4,1)), ord(substr($firmware,5,1)), ord(substr($firmware,6,1)), ord(substr($firmware,7,1)), ord(substr($firmware,8,1))); printf("\n"); $S=substr($S, 72); # There are up to 8 scans reported, each takes 42 bytes printf("SSID MAC channel strength\n"); while ($S) { ($SSID, $MAC, $channel, $strength) = unpack("A32 H12 c1 c1", $S); # A nonzero MAC means that there was something found in this slot if ($MAC != "000000000000") { printf("%-12s %-12s %2d %3d\n", $SSID, $MAC, $channel, $strength); } $S=substr($S, 42); }' done