If the mountain doesn’t go to Magomed ... How to maintain an active ADSL connection with a curved arm provider

    It so happened that negotiations with the provider that the connection is sometimes lost, and the ADSL modem does not notice this fact, did not lead to anything. I had to look for other ways.

    Task : Programmatically restart the ADSL modem when the connection is lost in order to force the reinstallation of the PPPoE session.

    The solution below has been tested on the D-link DSL 2640U ADSL modem, but I think it can be easily adapted for any other ADSL modem models.



    So, the solution is a php script that checks every 5 minutes for a connection to the ping site of the provider.
    If there is no ping, send a reboot command to the ADSL modem.

    Using Windows XP, it is quite problematic to run the script every 5 minutes. Therefore, a free Sheduler was used.Splinterware System Scheduler .

    For simplicity, suppose that Denwer is installed on the computer and all the files are located in Z: \ home \ inet-keeper \ www \

    Solution:
    In the above directory we have

    1) the inet-keeper.bat file that runs every 5 minutes from the System Scheduler
    file inet-keeper.bat launches the php script of the same name: 2) inet-keeper.php file the contents of the inet-keeper.php file: If the provider’s site (google.com in the above example) stops responding, the script starts the modem to reboot, opening page 192.168.1.1/rebootinfo.cgi Since modem requires authorization in send_request functions have a string specifying the user name and pairs l
    z:\usr\bin\php -n -f inet-keeper.php >> inet-keeper.log




    set_time_limit(60*5);

    $res = exec("ping google.com -n 10", $output, $var);
    $output = date('r');
    $output .= " ## Ping result: $var"; // 0-ОК 1-Error
    $output .= " ## $res";
    if ($var || substr_count($res, '= 0ms') == 3) // In case like Minimum = 0ms, Maximum = 0ms, Average = 0ms
    {
    $error = true;
    $output .= " ## Error detected!";
    $output .= "\nRebooting modem...\n";
    reboot_modem();
    }
    $output .= "\n";

    if ($error) // or true)
    echo $output;

    function reboot_modem()
    {
    $log = send_request("getlog");
    file_put_contents("logs\\" . date('Y-M-d_H-i-s') . ".html" ,$log);
    send_request("reboot");
    }

    function send_request($r) {
    $login = "admin";
    $password = "admin";
    $auth = base64_encode($login . ":" . $password);
    $fp = fsockopen('192.168.1.1', 80, $errno, $errstr, 60);
    if ($fp)
    {
    switch ($r) {
    case "reboot":
    $out = "GET /rebootinfo.cgi HTTP/1.0\r\n";
    break;
    case "getlog":
    $out = "GET /logview.cmd HTTP/1.0\r\n";
    break;
    default:
    return;
    }
    $out .= "Host: 192.168.1.1\r\n";
    $out .= "Authorization: Basic $auth\r\n";
    $out .= "Connection: Close\r\n\r\n";
    // посылаем запрос
    fwrite($fp, $out);
    $html = "";

    while (!feof($fp)){
    $part=fgets($fp);
    $html.=$part;
    }
    fclose($fp);
    }
    return $html;
    }
    ?>





    $login = "admin";
    $password = "admin";


    When the modem is reloaded, there will be
    1) an entry about this in the inet-keeper.log file
    2) in the subdirectory log the contents of the system log page of the modem (in my case, the contents of the page 192.168.1.1/logview.cmd )

    Also popular now: