-
-
Save joshbode/6f7a8aec81f92e96bd6b 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
#! /usr/bin/env bash | |
GREP=ggrep | |
# parameters | |
BAND=$1 | |
CHANNEL=${2:-0} | |
# determine the router ip | |
ROUTER=$(netstat -nr | $GREP -oP '(?<=^default) +[^ ]+' | $GREP -oP '[^ ]+') | |
# get username/password from .netrc | |
NETRC=${NETRC:-$HOME/.netrc} | |
USERNAME=$($GREP -zoP "(?<=^machine $ROUTER\n login ).+$" "$NETRC") | |
PASSWORD=$($GREP -zoP "(?<=^machine $ROUTER\n login $USERNAME\n password ).+$" "$NETRC") | |
# defaults for wlan | |
declare -A WLAN_DEFAULTS | |
WLAN_DEFAULTS=( | |
[WirelessEnable]=1 | |
[OutputPower]=100 | |
[NMode]=1 | |
[restoreWirelessDefaults]=0 | |
[commitwlanRadio]=1 | |
) | |
# parsing regexes | |
declare -A CHECK | |
CHECK=( | |
[band]='(?<=Current : )\d(\.\d)? GHz' | |
[channel]='(?<=Current : )\d+(?= \*\*\*Interference Level: )' | |
[int]='(?<=Interference Level: )\w+' | |
) | |
# strip values from output | |
function check() { | |
curl -s http://$ROUTER/wlanRadio.asp | $GREP -aoP "${CHECK[$1]}" | |
} | |
# login | |
curl -d "loginUsername=$USERNAME&loginPassword=$PASSWORD" http://$ROUTER/goform/login | |
# update settings | |
if [[ $1 != "" ]]; then | |
echo -n "$(check band) ($(check channel)) -> " | |
QUERY="Band=$BAND&ChannelNumber=$CHANNEL" | |
QUERY=${QUERY}$(for x in "${!WLAN_DEFAULTS[@]}"; do echo -n "&$x=${WLAN_DEFAULTS[$x]}"; done) | |
curl -d "$QUERY" http://$ROUTER/goform/wlanRadio | |
fi | |
# check state | |
echo "$(check band) ($(check channel))" | |
echo "Interference: $(check int)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment