Linux鯖がある人なら、bash+expectで処理するのが賢いかもだけど、
ほかのWeb設定あるルータにも応用できるのでphp版。pearのHTTPRequest必要。
エラー処理は省略したので適当に修正してください。以下、チラ裏。
<?php
$RTID = "xxxxx"; // ルータログインID
$RTPW = "xxxxxxxx"; // ルータログインPW
$RTIP = "xxx.xxx.xxx.xxx"; // ルータIPアドレス
$HOST = "****.dip.jp"; // 接続先ホスト名
$nowIP = gethostbyname($HOST);
require_once("HTTP/Request.php");
$req =& new HTTP_Request("http://{$HOST}/show_config.htm");
$req->setBasicAuth($RTID, $RTPW);
$res = $req->sendRequest();
$res = $req->getResponseBody();
preg_match("/<PRE>(.+)</PRE>/s", $res, $match);
preg_match("/ipsec 1 policy dstgwip (([0-9]+\.){3}[0-9]+)/s", $match[1], $match2);
if ( $nowIP != $match2[1] ) {
$conf = preg_replace("/ipsec 1 policy dstgwip (([0-9]+\.){3}[0-9]+)/s", $nowIP , $match[1]);
$req =& new HTTP_Request("http://{$RTIP}/put-config.cgi");
$req->setBasicAuth($RTID, $RTPW);
$req->setMethod(HTTP_REQUEST_METHOD_POST);
$req->addPostData("config",$conf);
$res = $req->sendRequest();
sleep(1);
$req =& new HTTP_Request("http://{$RTIP}/reset.cgi");
$req->setBasicAuth($RTID, $RTPW);
$req->setMethod(HTTP_REQUEST_METHOD_POST);
$req->addPostData("reset","1");
$res = $req->sendRequest();
}
?>