php實(shí)現(xiàn)登錄tplink WR882N獲取IP和重啟的方法
來源:易賢網(wǎng) 閱讀:983 次 日期:2016-08-12 14:28:54
溫馨提示:易賢網(wǎng)小編為您整理了“php實(shí)現(xiàn)登錄tplink WR882N獲取IP和重啟的方法”,方便廣大網(wǎng)友查閱!

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

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

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

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

該腳本只適用WR882N, 其他型號(hào)未測(cè)試.

<?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(); // 啟動(dòng)一個(gè)CURL會(huì)話

  curl_setopt($curl, CURLOPT_URL, $url); // 要訪問的地址

  curl_setopt($curl, CURLOPT_HTTPHEADER, $header); //設(shè)置頭信息的地方

  curl_setopt($curl, CURLOPT_TIMEOUT, 60); // 設(shè)置超時(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;

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

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:php實(shí)現(xiàn)登錄tplink WR882N獲取IP和重啟的方法
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65317125(9:00—18:00) 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)