php實現登入tplink WR882N擷取IP和重啟的方法_php技巧

來源:互聯網
上載者:User

本文執行個體講述了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用法總結》、《phpRegex用法總結》、《php字串(string)用法總結》、《PHP數組(Array)操作技巧大全》、《PHP數學運算技巧總結》、《php物件導向程式設計入門教程》、《PHP資料結構與演算法教程》、《php程式設計演算法總結》及《php常見資料庫操作技巧匯總》

希望本文所述對大家PHP程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.