php
  • curl
  • wifi
  • router
  • 2014-06-18 32 views 0 likes 
    0

    我正在爲我的路由器構建一個web應用程序,這將是我的學士論文。如何使用cURL和PHP獲取路由器信息

    壞的是我無法使用我的cURL函數顯示路由器的信息,因爲我得到了錯誤的路由器用戶名和密碼錯誤。我沒有發現任何問題都:

    捲曲功能:

    function myCurl($url, $post="") 
    { 
        global $status; 
    
    
    
    $header = 'Authorization: Basic YWRtaW46YWRtaW4='; 
    
    $cookiepath_tmp = "c:/xampp/htdocs/wifi/cookie.txt"; 
    
    $resp = array(); 
    
    $ch = curl_init(); 
    
    curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1"); 
    curl_setopt($ch,CURLOPT_URL, trim($url)); 
    curl_setopt($ch,CURLOPT_REFERER, trim($url)); 
    curl_setopt($ch,CURLOPT_COOKIEJAR,$cookiepath_tmp); 
    curl_setopt($ch,CURLOPT_COOKIEFILE,$cookiepath_tmp); 
    curl_setopt($ch,CURLOPT_COOKIESESSION, true); 
    curl_setopt($ch,CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); 
    curl_setopt($ch,CURLOPT_MAXREDIRS, 10); 
    curl_setopt($ch,CURLOPT_ENCODING, ""); 
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 
    #curl_setopt($ch,CURLOPT_AUTOREFERER, true); 
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 15); 
    curl_setopt($ch,CURLOPT_TIMEOUT, 15); 
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch,CURLOPT_HEADER, 0); 
    curl_setopt($ch,CURLOPT_HTTPHEADER, array('Expect:')); 
    curl_setopt($ch,CURLOPT_VERBOSE, 1); 
    #curl_setopt($ch,CURLOPT_FAILONERROR, true); 
    
    if($post) { curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,$post); } 
    
    $returned = curl_exec($ch); 
    $resp['returned'] = $returned; 
    
    $status=curl_getinfo($ch); 
    $resp['status'] = $status; 
    curl_close($ch); 
    
    
    return $resp; 
    } 
    

    我想用PHP來顯示信息:

    的PHP代碼:

    <?php echo $success_msg; 
         $url = "http://192.168.0.1/session.cgi"; 
         $post = "REPORT_METHOD=xml&ACTION=login_plaintext&USER=admin&PASSWD=admin&CAPTCHA="; 
         $data = myCurl($url, $post); 
    
         #$url = "http://192.168.0.1/st_log.php"; 
         #$data = myCurl($url); 
         echo $data['returned']; 
    
         ?> 
    

    錯誤是:

    Username or Password is incorrect. 
    

    但是,用戶名和密碼admin是正確的。

    我加入以下代碼myCurl功能,但仍然不能正常工作:

    $header = 'Authorization: Basic YWRtaW46YWRtaW4='; 
    YWRtaW46YWRtaW4= is the encoded username:password in Base64. 
    

    最後編輯時間: 我的CURLOPT_HEADER設置爲true,和我有顯示這樣的文字:

    HTTP/1.1 501 Not Implemented Server: Router Webserver Connection: close WWW-Authenticate: Basic realm="TP-LINK Wireless Lite N Router WR740N" Content-Type: text/html 
    

    任何解決方案?

    我真的很感謝你的幫忙!謝謝!

    回答

    0

    我不知道什麼是您的路由器(供應商/型號),但其中大多數使用HTTP basic authentication。而且,當身份驗證爲空或錯誤時,您會得到一個HTTP 401 error: Unauthorized,它可能對應於您的錯誤字符串。

    所以,你應該嘗試插入HTTP authorization header in the cURL request

    Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== 
    
    +0

    我已經添加了授權用戶名:在Base64編碼的密碼,但仍然無法正常工作。 – toofast

    相關問題