Table of Contents
機能
Earth Dynamic DNSに登録した情報を更新するスクリプトです。
ダウンロード
updateEarth.cgi
#!/usr/local/bin/perl
# Earth DynamicDNS の更新スクリプト
$sUserName = 'username'; # ユーザ名
$sPassword = 'password'; # パスワード
$sSubDomain = 'subdomain'; # サブドメイン
$sDomain = 'mydns.to'; # ドメイン
#$sDomain = 'ur.to';
$sMXHost = ''; # メールホスト
$sMX = 'f'; # メールサーバ t:使う f:使わない
$sWildcard = 't'; # ワイルドカード t:使う f:使わない
# 成功した場合の結果
$sFileSuccess = 'updateEarth_success.log';
# IPアドレスを調べるサービスを行うアドレス
$sIPCheckURI = 'http://www02.so-net.ne.jp/~shintan/gateway/ipcheck.cgi';
open( IN, $sFileSuccess ) || die( "can't open '".$sFileSuccess."'\n" );
@lines = <IN>;
close( IN );
$sSuccessLog = join( "", @lines );
$sMyIP = &getURI( $sIPCheckURI );
if ( $sMyIP =~ /(\d+\.\d+\.\d+\.\d+)/ ){
$sMyIP = $1;
$sEarthUpdateURI = 'http://' . $sUserName . ':' . $sPassword
. '@mydns.to/member/domainedit.php?ip=' . $sMyIP
. '&mxhost=' . $sMXHost . '&mx=' . $sMX . '&wc=' . $sWildcard
. '&domain=' . $sDomain . '&subdomain=' . $sSubDomain . '&mode=e';
$sResult = &getURI( $sEarthUpdateURI );
if ( $sResult ne $sSuccessLog ){
print "Content-type: text/html; charset=Shift_JIS\n\n";
print $sResult."\n";
} else {
# 成功したときは何もしない
}
} else {
print "Content-type: text/plain; charset=Shift_JIS\n\n";
print "can't get my IP.\n";
}
exit();
# --- Subroutine ---
sub getURI {
my( $URI ) = @_;
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$req = HTTP::Request->new( GET => $URI);
# send request
$res = $ua->request( $req );
# check the outcome
if ( $res->is_success ){
return $res->content;
} else {
return "Error: " . $res->status_line . "\n";
}
}
# EOF
ipcheck.cgi
#!/usr/local/bin/perl
print "Content-type: text/plain; charset=Shift_JIS\n\n";
$remote_addr = $ENV{"REMOTE_ADDR"};
printf( "%s", $remote_addr );
exit();
# EOF