[英]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.