#!/usr/bin/perl use POSIX qw(strftime); ###CONFIG### my $ext_if = "eth1"; my $log = "/home/bitrot/dynip"; my $zone = "pengu.in"; ###END CONFIG### my $cur_ip = `/sbin/ifconfig $ext_if|grep inet|grep -v inet6|awk '{print \$2}'|sed -e 's|addr:||'`; my $now_time = strftime "%m-%d-%Y-%H:%M:%S", localtime; my $noup=0; chomp($cur_ip); if (!-e $log) { `touch $log`; open(WRITE, ">$log") or die "$file cannot be opened for writing."; printf WRITE "$now_time" . "->$cur_ip\n"; close(WRITE); } open(READ, "<$log") or die "$file cannot be opened ."; while () { $_ =~ m/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/; $old_ip = $1; if ("$1" eq "$cur_ip") { :x } else { $noup=0; open(WRITE, ">$log") or die "$file cannot be opened."; printf WRITE "$now_time" . "->$cur_ip\n"; close(WRITE); } } close(READ); if ($noup == 1) { print "IP has not changed."; } else { print "Old IP: $old_ip\nNew IP: $cur_ip\nUpdating DNS Zone.\n"; `echo -e "server 127.0.0.1\nzone pengu.in\nupdate delete $zone 60 in A $old_ip\nsend|nsupdate"` `echo -e "server 127.0.0.1\nzone pengu.in\nupdate add $zone 60 in A $cur_ip\nsend|nsupdate"` }