#!/usr/bin/perl -w # Update dyndns.dk by Ian Kumlien # No more running a browser every hour, check the ip first.... # # Usage, copy the file to /etc/cron.hourly/ # # don't forget to create the /var/dyndns/ directory # use IO::Socket; use IO::Interface ':functions'; require LWP::UserAgent; # usernane? my $name = ""; # password? my $password = ""; my $url = "http://dyndns.dk/opdat"; # what networking card? my $if = "eth0"; # force update in how many days? my $days = 3; # ---------------------------------------------------------------------------- # Don't edit here unless you know what you are doing. # ---------------------------------------------------------------------------- my $s = IO::Socket::INET->new(Proto => 'udp'); my ($fh, $ua, $res); my $old_ip = "0.0.0.0"; if(open($fh, "/var/dyndns/addr-$if")) { unless ((time - (stat($fh))[9]) > ($days * 86400)) { sysread($fh, $old_ip, '17'); } close($fh); } unless($s->if_addr($if) eq $old_ip) { print "Not matching, starting update\n"; $ua = new LWP::UserAgent; $ua->timeout(60); $res = $ua->get("$url?name=$name&pw=$password&silent=1"); unless($res->is_error) { print "Update succeded!\n"; if(open($fh, '>', "/var/dyndns/addr-$if")) { syswrite($fh, $s->if_addr($if)); close($fh); } } }