P-2601HN-F1 router reboot script

I recently needed a way to automatically reboot my router every night. There were however no build-in way to do this in the router provided by my ISP. My router is a P-2601HN-F1. Therefore I was forced to write my own reboot script. I choose to make the script in PHP language, which I can execute directly from command line in Linux.

In the router there are two ways on administrating it. It can be done with the web interface, or it can be configured via telnet on port 23023. I choose the latter, as it is easy to create a socket connection in PHP. Therefore the script looks like this.

$host   = '';
$port   = '23023';
$user   = 'xxxx';
$pass   = 'xxxx';

$socket = fsockopen($host, $port) or die('Could not connect to: '.$host);

$cnt = 0;
while (!feof ($socket)) {
  $line = fgets($socket, 8192);
  sleep (0.5);
  if (ereg ("ogin", $line) || $cnt == 1) {
       fputs($socket, $user."\n");
       $line = fgets($socket, 8192);
       fputs($socket, $pass."\n");
    if ($cnt == 4)
       fputs($socket, "reboot\n");

Leave a Reply