Home > php教程 > PHP开发 > body text

How to implement php login to tplink WR882N to obtain IP and restart

高洛峰
Release: 2016-12-28 16:20:33
Original
2114 people have browsed it

The example of this article describes the method of php to log in to tplink WR882N to obtain IP and restart. Share it with everyone for your reference, the details are as follows:

As soon as the server uploads big data tplink WR882N is easily stuck, and then cannot access the Internet. We plan to check the server regularly. If it is found that the specified website cannot be accessed 10 times in a row, then Automatically execute the restart operation (this part is not implemented, please add it yourself).

After searching around, I found that there is only the old version of tplink login script. I tried it for a long time without success – the tplink 740N at home has no problem.

So I can only write it directly. The simple script is as follows, you can extend it by yourself

This script is only suitable for WR882N, other models have not been tested.

<?php
// TPLINK WR882N 管理脚本
function getContent($url)
{
  // 解悉url
  $temp = parse_url($url);
  $query = isset($temp[&#39;query&#39;]) ? $temp[&#39;query&#39;] : &#39;&#39;;
  $path = isset($temp[&#39;path&#39;]) ? $temp[&#39;path&#39;] : &#39;/&#39;;
  $header = array (
    "POST {$path}?{$query} HTTP/1.1",
    "Host: {$temp[&#39;host&#39;]}",
    "Content-Type: text/xml; charset=utf-8",
    &#39;Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8&#39;,
    &#39;Cookie: Authorization=Basic &#39; . base64_encode("admin:admin"),  // 注意这里的cookie认证字符串
    "Referer: http://{$temp[&#39;host&#39;]}/",
    &#39;User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1)&#39;,
    "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(&#39;/wanPara=new Array\((.+?)<\/script>/s&#39;,$content,$all);
  $ip = "0";
  if(!empty($all[1])){
    $data = trim($all[1]);
    $data = str_replace("\r\n","",$data);
    $data = explode(",",$data);
    $ip = str_replace(&#39;"&#39;,&#39;&#39;,$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;
Copy after login

I hope this article will help everyone with their PHP programs Design helps.

For more related articles on how to log in to tplink WR882N with php and get IP and restart, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!