#!/usr/bin/perl my $zoneFile = "/Users/ian/dns/db.ian"; my $ipLog = "/Users/ian/dns/iplog.txt"; my @ipdata = `/usr/local/bin/noip2 -S 2>&1`; # get IP foreach(@ipdata) { if ($_ =~ /\b(?:\d{1,3}\.){3}\d{1,3}\b/) { $ip = $&; } } # read zone file open(ZONE, "$zoneFile"); my @zoneData = ; close(ZONE); foreach(@zoneData) { # replace IP references $_ =~ s/\b(?:\d{1,3}\.){3}\d{1,3}\b/$ip/g; # find zone serial number if ($_ =~ m/([0-9]{10}).*serial/g) { $serial = $1; # get date ($Second, $Minute, $Hour, $Day, $Month, $Year) = localtime(time); $Year = 1900 + $Year; $Month++; if (length($Day) == 1) { $Day = "0" . $Day; } if (length($Month) == 1) { $Month = "0" . $Month; } # if date has changed then set new date and version 01 # else if date is the same then just increment serial if (substr($serial, 0, 8) eq "$Year$Month$Day") { $serial++; $_ =~ s/[0-9]{10}/$serial/g; } else { my $newSerial = "$Year$Month$Day" . "01"; $_ =~ s/[0-9]{10}/$newSerial/g; } } } # write new file open(ZONE, ">$zoneFile"); print ZONE @zoneData; close(ZONE); # write to log if ($ipLog ne "") { open(LOG, ">>$ipLog"); print LOG "$Year-$Month-$Day $Hour:$Minute --> changed to $ip\n"; close(LOG); } # kick BIND `rndc reload`;