繁体   English   中英

自动登录网络摄像机

[英]Auto-login into the IP Camera

我有一台网络摄像机,我想在我的网页上显示实时视图。

网络摄像机不允许匿名登录,所以我需要在连接时输入用户名和密码。

我有javascript:

<img src="http://user:password@camera_ip_address/cgi-bin/jpg/image.cgi?" width="640" height="480" name="refresh">

<script language="JavaScript" type="text/javascript">     
image = "http://camera_ip_address/cgi-bin/jpg/image.cgi?"
function Start() {
tmp = new Date();
tmp = "?"+tmp.getTime()
document.images["refresh"].src = image+tmp
setTimeout("Start()", 100)
}
Start();       
</SCRIPT>

它在 Firefox 中运行正常,但是:

http://user:password@camera_ip_number

在其他浏览器中不起作用(它会弹出一个表单以输入用户名和密码)。

但是在 PHP 中你可以使用 user:password 我已经使用以下方法检查过它:

<?php
header('Content-type: image/jpeg');
print( file_get_contents( 'http://user:password@camera_ip_address/cgi-bin/jpg/image.cgi?' ));
?>

当然它只显示一帧,但你不必输入用户名和密码。

如何使用 PHP 登录网络摄像机? 如果我可以在进入网页时登录一次,我的 javascript 将可以正常工作,因为浏览器会记住用户名和密码,直到我关闭浏览器。

我不知道如何发送用户名和密码来登录。

对不起我的英语。

好的,我已经使用 PHP 和 JavaScript 让它工作了。 也许这对其他人有帮助:

将 PHP 文件另存为,例如,snapshot.php:

<?php
$img="http://user:password@camera_ip/cgi-bin/jpg/image.cgi?"; 
header ('content-type: image/jpeg'); 
readfile($img); 
?> 

在 HTML 文件中,添加以下脚本:

<img src="http://domain.com/snapshot.php" width="640" height="380" name="refresh">

<script language="JavaScript" type="text/javascript">     
image = "http://domain.com/snapshot.php"
function Start() {
tmp = new Date();
tmp = "?"+tmp.getTime()
document.images["refresh"].src = image+tmp
setTimeout("Start()", 300)
}
Start();       
</script>

它在每个浏览器下都可以正常工作。 如果我将超时设置为小于 300,则会出现一些滞后。 我不知道为什么会这样; 也许互联网连接或网站速度。

您也许可以改用 Apache mod_rewrite - PHP 堆栈的开销更少,而且通常可能更快。 有关更多信息,请参阅此页面

选择其中之一。

Apache .htaccess - 您的页面请求http://yoursite/livecam/image.jpg ,它通过 Apache 的代理运行到您的相机。

RewriteEngine on
RewriteBase /livecam/
RewriteRule ^image.jpg$ http://user:password@camera_ip_address/cgi-bin/jpg/image.cgi [P]
ProxyPassReverse /livecam/image.jpg http://user:password@camera_ip_address/cgi-bin/jpg/image.cgi

在 PHP 中,创建一个名为 image.php 的文件 - 您的页面请求http://yoursite/image.php ,它将图像流式传输到任何请求它的地方。

<?php
$file = 'http://user:password@camera_ip_address/cgi-bin/jpg/image.cgi';

if (file_exists($file)) {
    header('Content-Type: image/jpeg');
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}  
?>

两者都将通过您的服务器代理图像。 在任何公共页面上提供用户名和密码通常是不好的做法,即使攻击者无法破坏任何相关内容。

请参阅PHP.net上的readfile()

您的代码看起来像(如果使用 Apache 版本,请将 image.php 替换为 livecam/image.jpg)。 我还稍微缩短了您的代码。

<img src="http://yourserver/image.php" width="640" height="480" name="refresh">
<script language="JavaScript" type="text/javascript">setTimeout(function() {document.images["refresh"].src = "http://yourserver/image.php?"+math.random();}, 100);</SCRIPT>
    IP:port/cgi-bin/jpg/image.cgi?&user=XXX&pwd=XXX
    IP:port/cgi-bin/jpg/image.cgi?&usr=XXX&pwd=XXX
    IP:port/snapshot.cgi?&user=XXX&pwd=XXX';
    IP:port/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=XXX&pwd=XXX';

尝试使用VLC播放器,将其插入页面并设置值

rtsp:// admin:password @ ipaddress

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM