e-smith-dynamicdns-dyndns/root/sbin/e-smith/dynamic-dns/dyndns

74 lines
1.7 KiB
Plaintext
Raw Normal View History

#!/usr/bin/perl
# Description: www.dyndns.com (commercial service)
######################################################
#
# Perl implementation of DYNDNS.COM's NamedControl Client.
#
# by Gunnar Hellekson <ghelleks@herne.drew.edu> 11/2/96
#
# based (heavily) on p.342 of the 1st Camel book
#
######################################################
($ip, $user, $pass, $domain) = @ARGV;
$AF_INET = 2;
$SOCK_STREAM = 1;
$SIG{'INT'} = 'dokill';
sub dokill {
kill 9,$child if $child;
}
$sockaddr = "S n a4 x8";
(
chop($ip = `/sbin/ifconfig ppp0 | /bin/grep inet | /usr/bin/cut -f2 -d: | /usr/bin/cut -c1-15`) &&
$ip =~ s/\s+//g
) unless $ip;
$user = "username" unless $user;
$pass = "password" unless $pass;
$domain = "dyndns.com" unless $domain;
# Added by JMorrison so that this works properly for dynamic DNS or
# dynamic domain services:
if ($user ne 'postmaster')
{
$domain = 'dyndns.com';
}
$info = pack("a20", $user) . pack("a20", $pass) . pack("a16", $ip) . pack("a64", $domain);
($name, $aliases, $proto) = getprotobyname('tcp');
($name, $aliases, $port) = getservbyname(50, 'tcp') unless $port =~ /^d+$/;
($name, $aliases, $type, $len, $thisaddr) = gethostbyname(chop($hostname = `/bin/hostname`));
($name, $aliases, $type, $len, $thataddr) = gethostbyname("dyndns.com");
$this = pack($sockaddr, $AF_INET, 0, $thisaddr);
$that = pack($sockaddr, $AF_INET, 50, $thataddr);
socket(S, $AF_INET, $SOCK_STREAM, $proto) || die $!;
bind(S, $this) || die $!;
connect(S,$that) || die $!;
select(S); $| = 1; select(STDOUT);
if ($child = fork) {
print "Waiting for routing tables to update...\n";
sleep 10;
print S $info;
sleep 3;
do dokill();
}
else {
while (<S>) {
printf("%s", $_);
}
print;
}