Skip to content

Commit

Permalink
Check of WLAN state added for 2,4 and 5 Ghz network.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhubig committed Apr 6, 2018
1 parent 002428c commit f173d08
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 18 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ Example (Deactivates the 5Ghz on your FritzBox):

| Action | Parameter | Description |
| --- | --- | --- |
| WLAN_2G | 0 or 1 | Switching ON or OFF the 2,4 Ghz WiFi |
| WLAN_5G | 0 or 1 | Switching ON or OFF the 5 Ghz WiFi |
| WLAN | 0 or 1 | Switching ON or OFF the 2,4Ghz and 5 Ghz WiFi |
| WLAN_2G | 0 or 1 or STATE | Switching ON, OFF or checking the state of the 2,4 Ghz WiFi |
| WLAN_5G | 0 or 1 or STATE | Switching ON, OFF or checking the state of the 5 Ghz WiFi |
| WLAN | 0 or 1 or STATE | Switching ON, OFF or checking the state of the 2,4Ghz and 5 Ghz WiFi |
| REPEATER | 0 | Switching OFF the WiFi of the Repeater |
| REBOOT | Box or Repeater | Rebooting your Fritz!Box or Fritz!Repeater |

Expand Down
66 changes: 51 additions & 15 deletions fritzBoxShell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,28 @@ WLANstate() {
location="/upnp/control/wlanconfig1"
uri="urn:dslforum-org:service:WLANConfiguration:1"
action='SetEnable'
echo "Sending WLAN_2G $1"; curl -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'><NewEnable>$option2</NewEnable></u:$action></s:Body></s:Envelope>" -s > /dev/null
if [ $option2 = "0" ] || [ "$option2" = "1" ]; then echo "Sending WLAN_2G $1"; curl -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'><NewEnable>$option2</NewEnable></u:$action></s:Body></s:Envelope>" -s > /dev/null; fi # Changing the state of the WIFI

action='GetInfo'
if [ $option2 = "STATE" ]; then
curlOutput1=$(curl -s -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'></u:$action></s:Body></s:Envelope>" | grep NewStatus | awk -F">" '{print $2}' | awk -F"<" '{print $1}')
curlOutput2=$(curl -s -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'></u:$action></s:Body></s:Envelope>" | grep NewSSID | awk -F">" '{print $2}' | awk -F"<" '{print $1}')
echo "2,4 Ghz Network $curlOutput2 is $curlOutput1"
fi
fi

if [ $option1 = "WLAN_5G" ] || [ "$option1" = "WLAN" ]; then
location="/upnp/control/wlanconfig2"
uri="urn:dslforum-org:service:WLANConfiguration:2"
action='SetEnable'
echo "Sending WLAN_5G $1"; curl -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'><NewEnable>$option2</NewEnable></u:$action></s:Body></s:Envelope>" -s > /dev/null
if [ $option2 = "0" ] || [ "$option2" = "1" ]; then echo "Sending WLAN_5G $1"; curl -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'><NewEnable>$option2</NewEnable></u:$action></s:Body></s:Envelope>" -s > /dev/null; fi # Changing the state of the WIFI

action='GetInfo'
if [ $option2 = "STATE" ]; then
curlOutput1=$(curl -s -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'></u:$action></s:Body></s:Envelope>" | grep NewStatus | awk -F">" '{print $2}' | awk -F"<" '{print $1}')
curlOutput2=$(curl -s -k -m 5 --anyauth -u "$BoxUSER:$BoxPW" http://$BoxIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'></u:$action></s:Body></s:Envelope>" | grep NewSSID | awk -F">" '{print $2}' | awk -F"<" '{print $1}')
echo " 5 Ghz Network $curlOutput2 is $curlOutput1"
fi
fi
}

Expand All @@ -87,22 +101,44 @@ Reboot() {
if [[ "$option2" = "Repeater" ]]; then echo "Sending Reboot command to $1"; curl -k -m 5 --anyauth -u "$RepeaterUSER:$RepeaterPW" http://$RepeaterIP:49000$location -H 'Content-Type: text/xml; charset="utf-8"' -H "SoapAction:$uri#$action" -d "<?xml version='1.0' encoding='utf-8'?><s:Envelope s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Body><u:$action xmlns:u='$uri'></u:$action></s:Body></s:Envelope>" -s > /dev/null; fi
}

DisplayArguments() {
echo ""
echo "Invalid Action and/or parameter. Possible combinations:"
echo ""
echo "|----------|-----------------|----------------------------------------------------------------------|"
echo "| Action | Parameter | Description |"
echo "|----------|-----------------|----------------------------------------------------------------------|"
echo "| WLAN_2G | 0 or 1 or STATE | Switching ON, OFF or checking the state of the 2,4 Ghz WiFi |"
echo "| WLAN_5G | 0 or 1 or STATE | Switching ON, OFF or checking the state of the 5 Ghz WiFi |"
echo "| WLAN | 0 or 1 or STATE | Switching ON, OFF or checking the state of the 2,4Ghz and 5 Ghz WiFi |"
echo "| REPEATER | 0 | Switching OFF the WiFi of the Repeater |"
echo "| REBOOT | Box or Repeater | Rebooting your Fritz!Box or Fritz!Repeater |"
echo "|----------|-----------------|----------------------------------------------------------------------|"
echo ""
}

# Check if an argument was supplied for shell script
if [ $# -eq 0 ]
then
echo "No argument supplied. See readme (https://github.com/jhubig/FritzBoxShell/blob/master/README.md) for all possible actions and parameters."
DisplayArguments
elif [ -z "$2" ]
then
echo "Second argument needed. See readme (https://github.com/jhubig/FritzBoxShell/blob/master/README.md) for all possible actions and parameters."
fi

#If argument was provided, check which function to be called
if [ "$option1" = "WLAN_2G" ] || [ "$option1" = "WLAN_5G" ] || [ "$option1" = "WLAN" ]; then
if [ "$option2" = "1" ]; then WLANstate "ON"; fi
if [ "$option2" = "0" ]; then WLANstate "OFF"; fi
elif [ "$option1" = "REPEATER" ]; then
if [ "$option2" = "1" ]; then RepeaterWLANstate "ON"; fi # Usually this will not work because there is no connection possible to the Fritz!Repeater as long as WiFi is OFF
if [ "$option2" = "0" ]; then RepeaterWLANstate "OFF"; fi
elif [ "$option1" = "REBOOT" ]; then
Reboot $option2
DisplayArguments
else
#If argument was provided, check which function to be called
if [ "$option1" = "WLAN_2G" ] || [ "$option1" = "WLAN_5G" ] || [ "$option1" = "WLAN" ]; then
if [ "$option2" = "1" ]; then WLANstate "ON";
elif [ "$option2" = "0" ]; then WLANstate "OFF";
elif [ "$option2" = "STATE" ]; then WLANstate "STATE";
else DisplayArguments
fi
elif [ "$option1" = "REPEATER" ]; then
if [ "$option2" = "1" ]; then RepeaterWLANstate "ON"; # Usually this will not work because there is no connection possible to the Fritz!Repeater as long as WiFi is OFF
elif [ "$option2" = "0" ]; then RepeaterWLANstate "OFF";
else DisplayArguments
fi
elif [ "$option1" = "REBOOT" ]; then
Reboot $option2
else DisplayArguments
fi
fi

0 comments on commit f173d08

Please sign in to comment.