我试图在 CURL 的帮助下使用 PHP 自动登录并自动重启我的路由器,但即使用户和密码正确,它也总是返回“受保护的对象”。该脚本是从本地主机测试的,没有防火墙:
<?php
$host = "192.168.1.250";
$user = "reboot";
$pass = "default";
$timeout = 10;
$user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_URL, "http://".$host."/restart.html");
//curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
echo $data; // always return "Protected Object"
?>