2012/04/10

[ ルーター再起動スクリプト - Windows PHP ]

ルーター再起動

最近回線の調子が悪くて、いちいちルーター管理画面開くのが面倒だったので、なんとなく作ってみた。

ルーターはNTT-ME系のなにか。。。


やっている事は単純で、Basic認証でルーター管理開いたら、切断・接続のフォームをPOSTしてあげるだけ。。。

書いている途中に気づいたが。。。再起動ではなかった(・ω・;、回線の切断と接続でした。

このPHPをbatで実行する感じに。

ルーターの管理画面のHTMLソースを見て何をPOSTで送っているか調べてみると自分用のができるかと思う。

PHPスクリプト

<?php
    include_once("HTTP/Request.php");
    $request_option=array(
        "timeout"=>"3600",
        "allowRedirects"=>true,
        "maxRedirects"=>5
    );
 
    $host="http://192.168.x.x/";
    $url="{$host}/cgi-bin/main.cgi?mbg_webname=pppconnect";
 
    $http = new HTTP_Request($url,$request_option);
    $http->setBasicAuth("username","password");
 
    $http->setMethod(HTTP_REQUEST_METHOD_POST);
    $http->addPostData("mbg_webname", "pppconnect");
    $http->addPostData("ppp_session", "1");
    $http->addPostData("mbg_disconnect", "切断");
 
    $response=$http->sendRequest();
    if(!PEAR::isError($response)){
        $ret_code=$http->getResponseCode();
        $ret_body=$http->getResponseBody();
    }
 
    sleep(3);
 
    $http->clearPostData();
    $http->setMethod(HTTP_REQUEST_METHOD_POST);
    $http->addPostData("mbg_webname", "pppconnect");
    $http->addPostData("ppp_session", "1");
    $http->addPostData("mbg_connect", "接続");
 
    $response=$http->sendRequest();
    if(!PEAR::isError($response)){
        $ret_code=$http->getResponseCode();
        $ret_body=$http->getResponseBody();
    }
    sleep(3);
 
?>

0 件のコメント:

コメントを投稿