欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-04-02 16:49:34
本文实例讲述了php实现登录tplink wr882n获取ip和重启的方法。分享给大家供大家参考,具体如下: 服务器一上传大数据tplink wr882n就容易卡住, 然...

本文实例讲述了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网络编程技巧总结》、《php curl用法总结》、《php socket用法总结》、《php正则表达式用法总结》、《php字符串(string)用法总结》、《php数组(array)操作技巧大全》、《php数学运算技巧总结》、《php面向对象程序设计入门教程》、《php数据结构与算法教程》、《php程序设计算法总结》及《php常见数据库操作技巧汇总

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