I have multiple NVR's (network video recoreders) at multiple places and I want to check from php if they up and working. I want to accomplish this by connecting to a web server of the NVR with the username and the password. I have created a username for example (you can connect to it, but please don't flood it):
Username: user
Password: A123456789
Login Page: http://31.168.115.100/doc/page/login.asp
by looking at the source code of the nvr I've noticed that the login button uses jquery, can it work with php? I've seen this code:
$data = array(
'username' => 'user',
'password' => 'A123456789'
);
$url = 'http://31.168.115.100/doc/page/login.asp';
$ch = curl_init($url);
$postString = http_build_query($data, '', '&');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
print($response);
but it does not work.
Another way of connecting is to get the response from rtsp protocol on port 554, but I always get an error from the server because of authentication. the rtsp url is rtsp://user:A123456789@31.168.115.100:554/Streaming/Channels/1201 this is working on vlc,
and the code is
function is_working($url){
$urlparsed = parse_url($url);
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if($socket == FALSE) return false;
if(@socket_connect($socket, $urlparsed['host'], $urlparsed['port'])){
$headers = array();
$headers[] = "DESCRIBE {$url} RTSP/1.0";
$headers[] = "User-Agent: WMPlayer/12.00.7600.16385 guid/3300AD50-2C39-46C0-AE0A-39E48EB3C868";
$headers[] = "Accept: application/sdp";
$headers[] = "Accept-Charset: UTF-8, *;q=0.1";
$headers[] = "X-Accept-Authentication: Negotiate, NTLM, Digest";
$headers[] = "Accept-Language: en-US, *;q=0.1";
$headers[] = "CSeq: 1";
$headerString = implode("\r\n", $headers) . "\r\n\r\n";
if(false === socket_write($socket, $headerString, strlen($headerString))){
socket_close($socket);
return 'false';
}else{
$response = '';
if(false === socket_recv($socket, $response, 2048,MSG_PEEK)){
socket_close($socket);
return false;
}else{
//var_dump($response);
if(strpos($response,"RTSP/1.0 200 OK") !== FALSE){
return 'connected';
}else{
return 'not connected';
}
socket_close($socket);
}
}
}else{
return 'false';
}
}
echo is_working("rtsp://user:A123456789@31.168.115.100:554/Streaming/Channels/1201");
What I'm trying to accomplish is to create a function that I write in the function the url, username, password and it will return to me if it connected or not.