Script for Rebooting FRITZ!Box

I recently came across a helpful script for rebooting a FRITZ!Box router, which I thought I’d share with the community. This script can be adapted for use with Shelly devices and is particularly useful for maintaining network stability. Here’s a brief overview of how it works:

The script sends a POST request to the FRITZ!Box’s UPnP control endpoint, triggering a reboot. It requires the user to input their FRITZ!Box credentials, which are used in the request. While this might seem a bit concerning, it’s a common practice for administrative tasks.

javascript
let user = “your_username”;
let password = “your_password”;
let host = “fritz.box”;
let port = 49000;

function reboot() {
Shelly.call(
“HTTP.Request”,
{
method: “POST”,
url: “http://” + user + “:” + password + “@” + host + “:” + port.toString() + “/upnp/control/deviceconfig”,
headers: {
“Content-Type”: ‘text/xml; charset=“utf-8”’,
SoapAction: “urn:dslforum-org:service:DeviceConfig:1#Reboot”,
},
body: [
‘<?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:Reboot xmlns:u=“urn:dslforum-org:service:DeviceConfig:1”></u:Reboot>’,
’ </s:Body>',
‘</s:Envelope>’,
].join(“”),
},
function (response, error_code, error_message) {
if (error_code !== 0) {
print(“Call failed with error " + error_code + " (” + error_message + "). ");
} else if (response.code !== 200) {
print(“Fritzbox responded with HTTP code " + response.code + " (” + response.message + "). ");
} else {
print("Fritzbox response: " + response.body);
}
},
);
}

reboot();

This script has been tested successfully with the FRITZ!Box 6490 Cable model. If you’re using a different model, please let me know if it works for you or if any adjustments are needed. I’m not an expert on FRITZ!Box internals, but I’m happy to help troubleshoot if possible!

If you have any feedback or improvements to suggest, feel free to share. Happy tinkering! :slight_smile: