服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|JavaScript|易语言|

服务器之家 - 编程语言 - PHP教程 - php实现登录tplink WR882N获取IP和重启的方法

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

2021-02-06 16:38lee PHP教程

这篇文章主要介绍了php实现登录tplink WR882N获取IP和重启的方法,涉及php基于curl的登陆及数据传输相关技巧,需要的朋友可以参考下

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

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

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

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

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?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程序设计有所帮助。

延伸 · 阅读

精彩推荐