ddo IP更新ツール

yum -y install lynx
cd /usr
mkdir -p ddns
cd ddns
vim ddo.jpIP_upgrade.pl

---------ここから-----------------------
#!/usr/bin/perl
#
# Check ip address, and update DDNS for "ddo.jp"
#
#

# parameters
# "ddo.jp" ID & PASSWD
local $ID = 'oasis6'; # Login ID(It serves as a domain name)
local $PASSWD = '19196969'; # Login password

# file names
local $CRT_IPF = '/tmp/CRT_IP2.dat';
local $LOG = '/var/log/ddns.log';

# Check current ip address on the appointed URL web page.
local $CHK_URL="http://info.ddo.jp/remote_addr.php";

#
#local $INTERVAL = 604800; # 1 weeks
local $INTERVAL = 300; # 5 minute

#
$ENV{'PATH'}="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin";

#---------------------------------------------------
# main
my ($NEW_IP,$CRT_IP,$CRT_TIME,$i);

# get current ip address which set as the domain.
$CRT_IP = "";
$CRT_TIME = "0";
open(INPUT, $CRT_IPF);
foreach(<INPUT>){
chop;
/^IP:/ && do{ $CRT_IP = $' };
/^TIME:/ && do{ $CRT_TIME = $' };
}
close(INPUT);

# check a assigned ip address
open(INPUT, "lynx -dump \"$CHK_URL\" | ");
foreach(<INPUT>){
/([0-9\.].*)/ && do{ $NEW_IP = $1};
}
close(INPUT);

# Lapsed time from the last update
$i = time() - $CRT_TIME;

# change DDNS, supposing the IP address is changed.
if ( ( ($NEW_IP ne "" )&&($CRT_IP ne $NEW_IP) ) || ( $i > $INTERVAL) ) {
# change DDNS
open(INPUT2,
"lynx -dump \"http://free.ddo.jp/dnsupdate.php?dn=$ID&ip=$NEW_IP&pw=$PASSWD\" |");

# check whether change of DDNS has been successful
foreach(<INPUT2>){
/SUCCESS: / && do{ $TEMP = 1;};
}
if( $TEMP == 1){
# save a new IP address.
$i = time();
open (OUTPUT ,">$CRT_IPF");
print OUTPUT "IP:$NEW_IP\nTIME:$i\n";
close OUTPUT;

# write a message on the log file
$time = conv_date(time());
open(LOG, ">> $LOG");
print(LOG $time . ":change \"" .
$ID . ".ddo.jp\" <= " . $NEW_IP . "\n");
close(LOG);
}
}

sub conv_date{
my ($times,$mode) = @_;
my ($sec,$min,$hour,$mday,$month,$year,$wday);

($sec,$min,$hour,$mday,$month,$year,$wday,undef,undef) = localtime($times);
$month++;
$year += 1900;
$times = sprintf("%d/%02d/%02d %02d:%02d", $year, $month, $mday,
$hour, $min);
return($times);
}
----------ここまで----------------------
chmod +x ddo.jpIP_upgrade.pl
cd
/usr/ddns/ddo.jpIP_upgrade.pl

crontab -e
2,7,12,17,22,27,32,37,42,47,52,57 * * * * /usr/ddns/ddo.jpIP_upgrade.pl

 COMMENT

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

NO IMAGE

カレントディレクトリ以下に存在するファイルやディレクトリ数のカウント

NO IMAGE

コマンドラインで特定の拡張子のファイルの文字列を一括でreplace(置換)する

NO IMAGE

Unknown collation: ‘utf8mb4_unicode_520_...

NO IMAGE

1625番のプロセスを強制終了する。yum の強制終了など

NO IMAGE

増設したHDDがつながらないなどの対処

ウェブサーバのバージョンやエンジンを調べてみる

抜け毛対策