#!/usr/local/bin/perl -w
# This little script uses ddup to keep the dyndns record uptodate.
# It will only update if the IP has changed!
# It also needs an extra perl module called LWP::Simple.
# complaints to giggel@mugiri.de
use strict;
use LWP::Simple;
# configure me!
my $datafile = "/var/db/dynip.dat";
my $dynhost = "foo.dyndns.org";
my $dynhost2 = "bar.dyndns.org";
my $debug = 1;
my $content = get("http://checkip.dyndns.org");
# stop configuring here
if (defined($content)) {
$content =~ /(\d+\.\d+\.\d+\.\d+)/;
my $ip = $1;
my $oldip = readip();
writeip($ip);
print "current IP is $ip\n" if ($debug);
print "last recorded IP was $oldip\n" if ($debug);
unless ($ip eq $oldip) {
print "need to update\n" if ($debug);
# print "ddup --host $dynhost --ip $ip --mx $dynhost --wildcard";
`/usr/local/sbin/ddup --host $dynhost --ip $ip --mx $dynhost --wildcard`;
print if ($debug);
# print "ddup --host $dynhost2 --ip $ip --mx $dynhost2 --wildcard";
`/usr/local/sbin/ddup --host $dynhost2 --ip $ip --mx $dynhost2 --wildcard`;
print if ($debug);
}
} else {
print "bad\n";
}
sub readip {
open(IN, "<".$datafile) || die "Can't open $datafile for reading: ".$!;
my $ip = <IN>;
close IN;
return $ip;
}
sub writeip {
my $ip = shift;
open(OUT, ">".$datafile) || die "Can't open $datafile for writing: ".$!;
print OUT $ip;
close OUT;
}