#!/usr/bin/perl -Tw use strict; use Socket; require Digest::MD5; import Digest::MD5 qw(md5_hex); ################################################################################ ### ### ddnsupdate ### ### Mark Morley (mark@islandnet.com) ### Last update: October 29, 2001 ### ### !!! Requires the Digest::MD5 module !!! ### ### The username/password in this file are used *only* for updating the DDNS ### entry and (should) have no resemblance to any other account. Even so, you ### may want to install this script as "--x------" and owned by a user you ### trust (it does not need to be 'root') ### ################################################################################ ### Config section ### my $nameserver = "ns1.islandnet.com"; # Usually ns1.islandnet.com my $hostname = ""; # Hostname to update my $username = ""; # Your username my $password = ""; # Your password my $ipaddress = "default"; # Usually blank ### End of config section, no need to change anything below here ### ### Get name server's address my $addr = (gethostbyname( $nameserver ))[4] or die "Could not resolve $nameserver"; ### Create a socket socket( SOCK, AF_INET, SOCK_STREAM, getprotobyname( "tcp" ) ) or die "Could not create socket!"; ### Connect to the name server connect( SOCK, sockaddr_in( 3495, $addr ) ) or die "Could not open connection to $nameserver"; ### Set socket and stdout to flush after every line select( SOCK ); $| = 1; select( STDOUT ); $| = 1; ### If an IP address is supplied on the command line, use it. if( $#ARGV + 1 > 0 ) { $ipaddress = $ARGV[0]; } ### If the IP address is still blank, use this machine's current IP if( $ipaddress eq "" ) { my $addr = getsockname( SOCK ) or die "Could not get local IP address from socket (this shouldn't happen)"; my ($port,$ip) = sockaddr_in( $addr ); $ipaddress = inet_ntoa( $ip ); } ### Read the salt value from the name server my $salt = ; chop $salt; ### Hash the password with the salt $password = md5_hex( md5_hex( $password ) . '.' . $salt ); ### Are we requesting that the host be taken offline? if( $ipaddress eq "0.0.0.0" || $ipaddress eq "0" || $ipaddress eq "offline" ) { print SOCK "$username:$password:$hostname:1\n"; ### Or do we want the name server to figure out our IP? } elsif( $ipaddress eq "default" ) { print SOCK "$username:$password:$hostname:2\n"; ### Or are we specifying an IP ourselves? } else { print SOCK "$username:$password:$hostname:2:$ipaddress\n"; } ### Read the result $_ = ; chop; ### Close the socket close SOCK; ### If the result begins with "0" the update was successful if( /^0/ ) { print "Updated $hostname to $ipaddress\n"; ### If it begins with "2" then the host was taken offline } elsif( /^2/ ) { print "$hostname taken offline\n"; ### Otherwise it failed :-( } else { print "Failure\n"; }