欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php實現(xiàn)登錄tplink WR882N獲取IP和重啟的方法

 更新時間:2016年07月20日 10:24:17   作者:lee  
這篇文章主要介紹了php實現(xiàn)登錄tplink WR882N獲取IP和重啟的方法,涉及php基于curl的登陸及數(shù)據(jù)傳輸相關(guān)技巧,需要的朋友可以參考下

本文實例講述了php實現(xiàn)登錄tplink WR882N獲取IP和重啟的方法。分享給大家供大家參考,具體如下:

服務(wù)器一上傳大數(shù)據(jù)tplink WR882N就容易卡住, 然后上不了網(wǎng). 打算在服務(wù)器定時檢測, 如發(fā)現(xiàn)連續(xù)10次無法訪問指定網(wǎng)站, 則自動執(zhí)行重啟操作(該部分未實現(xiàn), 請自己添加).

gg了一圈發(fā)現(xiàn)只有舊版的tplink登錄腳本, 試了很久沒成功 – 家里的tplink 740N倒是沒問題.

于是只能直接寫了, 簡單的腳本如下, 可自己擴(kuò)展

該腳本只適用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認(rèn)證字符串
    "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); //設(shè)置頭信息的地方
  curl_setopt($curl, CURLOPT_TIMEOUT, 60); // 設(shè)置超時限制防止死循環(huán)
  curl_setopt($curl, CURLOPT_HEADER, 0); // 顯示返回的Header區(qū)域內(nèi)容
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 獲取的信息以文件流的形式返回
  $content = curl_exec($curl); // 執(zhí)行操作
  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;

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《php curl用法總結(jié)》、《php socket用法總結(jié)》、《php正則表達(dá)式用法總結(jié)》、《php字符串(string)用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計算法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設(shè)計有所幫助。

相關(guān)文章

最新評論