#!/usr/bin/perl
use
constant
HOSTNAME
=>
'puerto.brock-family.org'
;
use
constant
ROUTER_PATTERN
=>
qr/(\d+\.\d+\.\d+\.\d+)/
;
use
constant
ZONEEDIT_USER
=>
'userfoo'
;
my
$cache_file
= catfile(tmpdir,
"zoneedit.ip"
);
my
$old_ip
=
''
;
if
(
open
(
my
$inp
,
"< $cache_file"
)) {
chomp
(
$old_ip
= <
$inp
>);
}
else
{
warn
"Can't read $cache_file: $!\n"
;
}
if
(get(ROUTER_PAGE) =~ ROUTER_PATTERN) {
my
$ip
= $1;
if
(
$ip
ne
$old_ip
) {
print
"IP address changed: $old_ip -> $ip\n"
;
if
(DNS::ZoneEdit->new->update(
username
=> ZONEEDIT_USER,
password
=> ZONEEDIT_PASS,
hostname
=> HOSTNAME,
)) {
print
"Update succeeded\n"
;
if
(
open
(
my
$outp
,
"> $cache_file"
)) {
print
$outp
"$ip\n"
;
}
else
{
warn
"Can't write $cache_file: $!\n"
;
}
}
else
{
print
"Update failed: [$@]\n"
;
}
}
else
{
print
"IP still $ip\n"
;
}
}
else
{
warn
"Could not get IP"
;
}