本文實(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è)試.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<?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ì)有所幫助。