z:\usr\bin\php -n -f inet-keeper.php >> inet-keeper.log
<?php
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('YM-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";
Source: https://habr.com/ru/post/96158/