《PHP學(xué)習(xí):php實(shí)現(xiàn)登錄tplink WR882N獲取IP和重啟的方法》要點(diǎn):
本文介紹了PHP學(xué)習(xí):php實(shí)現(xiàn)登錄tplink WR882N獲取IP和重啟的方法,希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
本文實(shí)例講述了php實(shí)現(xiàn)登錄tplink WR882N獲取IP和重啟的方法.分享給大家供大家參考,具體如下:PHP應(yīng)用
服務(wù)器一上傳大數(shù)據(jù)tplink WR882N就容易卡住, 然后上不了網(wǎng). 打算在服務(wù)器定時(shí)檢測(cè), 如發(fā)現(xiàn)連續(xù)10次無(wú)法訪問(wèn)指定網(wǎng)站, 則自動(dòng)執(zhí)行重啟操作(該部分未實(shí)現(xiàn), 請(qǐng)自己添加).PHP應(yīng)用
gg了一圈發(fā)現(xiàn)只有舊版的tplink登錄腳本, 試了很久沒(méi)成功 C 家里的tplink 740N倒是沒(méi)問(wèn)題.PHP應(yīng)用
于是只能直接寫(xiě)了, 簡(jiǎn)單的腳本如下, 可自己擴(kuò)展PHP應(yīng)用
該腳本只適用WR882N, 其他型號(hào)未測(cè)試.PHP應(yīng)用
<?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); // 要訪問(wèn)的地址 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;
更多關(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è)計(jì)入門(mén)教程》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計(jì)算法總結(jié)》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》PHP應(yīng)用
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助.PHP應(yīng)用
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/5130.html