首页 > 语言 > PHP > 正文

php实现登录tplink WR882N获取IP和重启的方法

2024-05-04 23:48:28
字体:
来源:转载
供稿:网友

本文实例讲述了php实现登录tplink WR882N获取IP和重启的方法。分享给大家供大家参考,具体如下:

服务器一上传大数据tplink WR882N就容易卡住, 然后上不了网. 打算在服务器定时检测, 如发现连续10次无法访问指定网站, 则自动执行重启操作(该部分未实现, 请自己添加).

gg了一圈发现只有旧版的tplink登录脚本, 试了很久没成功 – 家里的tplink 740N倒是没问题.

于是只能直接写了, 简单的脚本如下, 可自己扩展

该脚本只适用WR882N, 其他型号未测试.

<?php// TPLINK WR882N 管理脚本function getContent($url){  // 解悉url  $temp = parse_url($url);  $query = isset($temp['query']) ? $temp['query'] : '';  $path = isset($temp['path']) ? $temp['path'] : '/';  $header = array (    "POST {$path}?{$query} HTTP/1.1",    "Host: {$temp['host']}",    "Content-Type: text/xml; charset=utf-8",    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',    'Cookie: Authorization=Basic ' . base64_encode("admin:admin"),  // 注意这里的cookie认证字符串    "Referer: http://{$temp['host']}/",    'User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1)',    "Content-length: 380",    "Connection: Close"  );  $curl = curl_init(); // 启动一个CURL会话  curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址  curl_setopt($curl, CURLOPT_HTTPHEADER, $header); //设置头信息的地方  curl_setopt($curl, CURLOPT_TIMEOUT, 60); // 设置超时限制防止死循环  curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回  $content = curl_exec($curl); // 执行操作  curl_close($curl);  return $content;}function getIp(){  $content = getContent("http://192.168.1.1/userRpm/StatusRpm.htm");  preg_match('/wanPara=new Array/((.+?)<//script>/s',$content,$all);  $ip = "0";  if(!empty($all[1])){    $data = trim($all[1]);    $data = str_replace("/r/n","",$data);    $data = explode(",",$data);    $ip = str_replace('"','',$data[2]);    $ip = trim($ip);  }  return $ip;}function reboot(){  $url = "http://192.168.1.1/userRpm/SysRebootRpm.htm?Reboot=%D6%D8%C6%F4%C2%B7%D3%C9%C6%F7";  getContent($url);}$info = getIp();echo $info;

希望本文所述对大家PHP程序设计有所帮助。


注:相关教程知识阅读请移步到PHP教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选