function send_get($ip, $port, $param = "") { $url = $ip . ":" . $port; // Проверка доступности хоста if (MyPing($url)) { // Если доступен, то отправляем param через HTTP log_cam(date('H:i:s') . " - Webcam {$ip} port {$port} is Ok "); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://{$ip}:{$port}/{$param}"); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); // $ansver = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); curl_close($ch); return true; } else { return false; } /* $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://{$ip}:{$port}/{$param}"); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); // curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $ansver = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); // echo "http://{$ip}:8080/{$param}"; // test $ansver = file_get_contents('ok'); // curl_close($ch); return $ansver; */ }
function ssh_exec($ip, $port, $param) { // HTTP version $url = $ip . ":" . $port; // Проверка доступности хоста if (MyPing($url)) { // Если доступен, то отправляем param через HTTP log_cam("Webcam {$ip} port {$port} is [ On-line ]", 'on-line'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://{$ip}:{$port}/{$param}"); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); // $ansver = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($ch); curl_close($ch); // var_dump($res); // print_r($res); return $res; } else { log_cam("Webcam {$ip} port {$port} is [ Off-line ]", 'off-line'); return false; } // end HTTP version // -- функция ssh_exec с подключение через SSH - работает, но не нужно /* // echo send_get($ip,$port); // Проверка доступности хоста в Винде или Линуксе. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { exec ("ping -n 2 -w 200 {$ip}", $output, $status); } else { exec ("ping -c 2 -w 200 {$ip}", $output, $status); } // Если доступен, то подключаемся через SSH if ($status == 0) { log_cam(date('H:i:s')." - Webcam {$ip} port {$port} is Ok "); //echo "Webcam {$ip} port {$port} is Ok <br />"; $connection = ssh2_connect($ip, $port); if ($connection){ if (ssh2_auth_password($connection, 'root', 'admin')) { ssh2_exec($connection, $command); return true; } else { return false; // Не прошла проверка логина_пароля // die('Public Key Authentication Failed'); } } else { log_cam(date('H:i:s')." - <b>Webcam {$ip} port {$port} is Off-line </b>"); //echo "<b>Webcam {$ip} port {$port} is Off-line </b><br />"; return false; // Не подключились к серверу } } */ // end с подключением через SSH }