3 # Linksys Wireless Router configuration commandline tool
5 # - WAP54G v3.1 with default firmware v3.04
12 curl
-sSi -u "$user:$pass" http
://$linksys_host/$1
13 #wget -q -O - --save-headers --http-user=$user --http-password=$pass http://$linksys_host/$1
16 get_page Setup_static.asp | perl
-e '
17 if(<> =~ /^.*\s401\b/) {
20 while(<>) { if($_ =~ /^f.GTK/) {
22 $var =~ s/^([^_]+_){2}([^\.]*)\..*$/$2/;
30 print join ".", ($ipaddr1, $ipaddr2, $ipaddr3, $ipaddr4);
31 print join ".", ($netmask1, $netmask2, $netmask3, $netmask4);
32 print join ".", ($gateway1, $gateway2, $gateway3, $gateway4);
36 query
="action=GTK_Submit"
37 for vars
in GTK_wl_devicename
:dn GTK_wan_ipaddr
:ipw GTK_wan_netmask
:nm GTK_wan_gateway
:gw GTK_lan_ipaddr
:ipl GTK_lan_dhcp
:dhcp
; do
41 if [ -n "$value" ]; then
42 query
="$query&$name=$value"
46 curl
-sSi -u "$user:$pass" -F "$query" http
://$linksys_host/sysconf.cgi |\
50 curl
-sSi -u "$user:$pass" -F "$1" http
://$linksys_host/sysconf.cgi |\
54 if [ "$npw" = "%" ]; then
55 read -s -e -p "New administration password: " pw1
57 read -s -e -p "Retype: " pw2
63 if [ .
"$pw1" != .
"$pw2" ]; then
66 if [ ${#pw1} -lt 4 -o ${#pw1} -gt 16 ]; then
70 query
="action=Apply&page=password"
71 for vars
in http_username
:un http_passwd
:pw1 confirm_http_passwd
:pw1
; do
75 if [ -n "$value" ]; then
76 query
="$query&$name=$value"
83 perl
-e 'exit 6 if("'"${mac_connect_to//\"/}"'" !~ /^([0-9A-F]{2}:){5}([0-9A-F]{2})$/i)'
84 query
="ap_mode=1&ap_client_mac=$mac_connect_to"
90 2) echo "$self: passwords mismatch" >&2;;
91 3) echo "$self: invalid length, ]4;16[" >&2;;
92 4) echo "$self: unauthorized, wrong password?" >&2;;
93 6) echo "$self: specify a MAC address, A1:2B:C3:4D:E5:6F" >&2;;
94 *) echo "$self: unhandled error" >&2;;
102 echo "$self [-option parameter] ... [host]
104 -u username to authenticate
105 -p password to authenticate
106 -p % prompt for password
107 --wan-ip dot-separated IPv4 decimal octets
112 -dhcp alias for --dhcp 0
113 +dhcp alias for --dhcp 1
114 --ssid valid SSID string
115 --device valid name for the device
116 -P set new admin password
117 -P % prompt for new admin password
119 --conn switch to AP client mode and connect to MAC
120 host hostname or ip address of Linksys router
126 --wan-ip) shift; ipw
=$1;;
127 --gateway) shift; gw
=$1;;
128 --netmask) shift; nm
=$1;;
129 --lan-ip) shift; ipl
=$1;;
130 --dhcp) shift; dhcp
=$1;;
133 --device) shift; dn
=$1;;
134 --ssid) shift; ssid
=$1;;
136 --conn) shift; mac_connect_to
=$1;;
147 if [ .
"$pass" = .
"%" ]; then
148 read -s -e -p "Router password: " pass
152 if [ -z "$linksys_host" ]; then
153 echo "$self: specify a host" >&2
155 elif [ -n "$npw" ]; then
158 elif [ -n "$ipw$gw$nm$ipl$dhcp$dn" ]; then
159 # if any variable set
161 elif [ $iwlist ]; then
162 get_page site_results.asp |
awk '/<!-- SiteSurvay Table start/,/<!-- SiteSurvay Table End/' | perl
-e '
163 if(<> =~ /^.*\s401\b/) {
167 if($_ =~ /<input type="(hidden|radio)"/) {
168 $_ =~ /name="([^\d"]+)(\d+)?"\s*value="([^"]*)"/;
173 $aps[$num]{$var} = $val;
174 #printf "%8s[%1s] = %s\n", ($var,$num,$val);
175 } elsif($_ =~ />(\d{1,3})%</) {
176 $aps[$num]{signal} = $1;
179 $count = $aps[0]{cnt};
180 printf "Networks: %2d\n------------\n", ($count);
183 printf "%s ch:%2d %32s %3d%% ", ($ap{ap}, $ap{channel}, $ap{ssid}, $ap{signal});
184 print "[WEP]" if($ap{wep}); print "[WPA]" if($ap{wpa});
189 elif [ -n "$mac_connect_to" ]; then