[expert] dyndns update script

2000-08-02 Thread Sheldon Lee Wen

Hi,

   I put together a quick script that will use the dyndns
ddns client to update a dyndns dynamic hostname (although
you could modify it to use something else and update a static
one too.) It does two things. 1st it checks to see if the
ip dns has matches the ip your service provider gave you
or dhcp has assigned you. It also checks to see how long it
has been since the last time you updated your dyndns entry.
(recall dhs's policies on updating you entry). If it has
been longer than 25 days or you ip has changed then it
updates it. 

I added modified this section of my ifup script (starting line 117)
to look like this:

if [ -n "$DHCP" ];then
echo -n "Determining IP information for $DEVICE via dhcpcd..."
if /sbin/dhcpcd $DEVICE -h $HOSTNAME ; then
echo " done."
echo -n "Checking Dynamic DNS Configuration...   "
/root/bin/up-dyndns $DEVICE #this is the script!
else
echo " failed."
exit 1
fi   

Hope this can help someone :)

Sheldon.
-- 
===
"... all thoughts of selfish desire, ill-will, hatred and
 violence are the result of a lack of wisdom ... "
 - Buddha

For an awsome fantasy role playing game checkout:
http://members.xoom.com/Lycadican
===

#!/usr/bin/perl

use Net::hostent;
use Socket;
use Env qw(HOSTNAME);

#
# User Configuration Variables  #
#

$command = "/usr/sbin/ddns --modify";
$config = "/etc/dyndns.conf";
$ifconfig = "/sbin/ifconfig";  

#
# Do NOT Edit below here unless you #
# know what you are doing!  #
#

$host = $ENV{HOSTNAME};
$DEVICE = $ARGV[0];

if ($DEVICE eq "") { die "Usage: up-dyndns device\n"; }

unless ($h = gethost($host)) {
warn "$0: no such host: $host\n";
}

# Processing config file
open (INPUT, "$config") || die "Unable to open $config for reading.\n";

   $day_data = INPUT;
   chop $day_data;
   ($temp,$date) = split('=',$day_data);
   ($last_day,$last_month,$last_year) = split('/',$date);

close (INPUT);

# Get our IP according to dns.
$dns_IP = inet_ntoa($h-addr);

# Get our actual IP according to ifconfig
open(IFCONFIG,"$ifconfig $DEVICE |") || die "Unable to get local IP address for 
$DEVICE.\n";
 
   $line = IFCONFIG;
   $line = IFCONFIG;
   ($temp,$line) = split(':', $line);
   $line =~ s/\s//g;
   $line =~ s/[A-Z]|[a-z]//g;
   $actual_IP = $line;

close (IFCONFIG);

# Find out how long it has been since we updated dyndns.
$age = find_age($last_day,$last_month,$last_year);

# Update dyndns and out config file if necessary.
if ( ($dns_IP != $actual_IP) || ( $age = 25 ) )
{
   print STDOUT "Updating Dynamic DNS from: $age days ago, Address: $dns_IP to 
$actual_IP \n";
   # update dyndns ip address
   open(OUPUT,"$command |") || die "Unable to execute ddns.\n";
  #@output = OUTPUT;
  #print "@output\n"; 
   close (OUTPUT);

   # update date in conf file
   ($sec, $min, $hour, $now_dd, $now_mm, $now_, $wday, $yday, $isdst) = localtime;
   $now_ += 1900;
   $now_mm++;
   open (OUTPUT, "$config") || die "Unable to open $config for writing.\n";
  print OUTPUT "DATE=$now_dd/$now_mm/$now_\n";
   close (OUTPUT);

}
else { print STDOUT "Dynamic DNS OK\n"; }


#  Subroutine to grab $mm and $dd and calculate the number of days since the last 
update 
sub find_age 
{
   $ = @_[2];
   $mm = @_[1]; 
   $dd = @_[0]; 

   # Get the current date.
   ($sec, $min, $hour, $now_dd, $now_mm, $now_, $wday, $yday, $isdst) = localtime;
   $now_mm++;
   $now_ += 1900;

   $find_age=0;
   $find_age=$find_age + $now_dd - $dd;

   if (($now_mm  $mm || ($now_mm == $mm  ($now_dd - $dd) = 0))  (int($find_age + 
0.5 + ($now_mm - $mm) * 30.41667) = 365)  $now_) * 12) + $now_mm) - 
((($) * 12) + $mm))  12) { $find_age = int($find_age + 0.5 + ($now_mm - $mm) * 
30.41667); } #less than a year
   else { $find_age = int($find_age + 0.5 + ($now_mm + (($now_ - $) * 12) - 
$mm) * 30.41667); }
   if ($mm == 2$now_mm != 2) { $find_age = $find_age - 2; } #month of February

   return $find_age;
} 




[expert] dyndns update script

2000-08-02 Thread Sheldon Lee Wen

Hi,

   I put together a quick script that will use the dyndns
ddns client to update a dyndns dynamic hostname (although
you could modify it to use something else and update a static
one too.) It does two things. 1st it checks to see if the
ip dns has matches the ip your service provider gave you
or dhcp has assigned you. It also checks to see how long it
has been since the last time you updated your dyndns entry.
(recall dhs's policies on updating you entry). If it has
been longer than 25 days or you ip has changed then it
updates it. 

I added modified this section of my ifup script (starting line 117)
to look like this:

if [ -n "$DHCP" ];then
echo -n "Determining IP information for $DEVICE via dhcpcd..."
if /sbin/dhcpcd $DEVICE -h $HOSTNAME ; then
echo " done."
echo -n "Checking Dynamic DNS Configuration...   "
/root/bin/up-dyndns $DEVICE #this is the script!
else
echo " failed."
exit 1
fi   

Hope this can help someone :)

Sheldon.
-- 
===
"... all thoughts of selfish desire, ill-will, hatred and
 violence are the result of a lack of wisdom ... "
 - Buddha

For an awsome fantasy role playing game checkout:
http://members.xoom.com/Lycadican
===

#!/usr/bin/perl

use Net::hostent;
use Socket;
use Env qw(HOSTNAME);

#
# User Configuration Variables  #
#

$command = "/usr/sbin/ddns --modify";
$config = "/etc/dyndns.conf";
$ifconfig = "/sbin/ifconfig";  

#
# Do NOT Edit below here unless you #
# know what you are doing!  #
#

$host = $ENV{HOSTNAME};
$DEVICE = $ARGV[0];

if ($DEVICE eq "") { die "Usage: up-dyndns device\n"; }

unless ($h = gethost($host)) {
warn "$0: no such host: $host\n";
}

# Processing config file
open (INPUT, "$config") || die "Unable to open $config for reading.\n";

   $day_data = INPUT;
   chop $day_data;
   ($temp,$date) = split('=',$day_data);
   ($last_day,$last_month,$last_year) = split('/',$date);

close (INPUT);

# Get our IP according to dns.
$dns_IP = inet_ntoa($h-addr);

# Get our actual IP according to ifconfig
open(IFCONFIG,"$ifconfig $DEVICE |") || die "Unable to get local IP address for 
$DEVICE.\n";
 
   $line = IFCONFIG;
   $line = IFCONFIG;
   ($temp,$line) = split(':', $line);
   $line =~ s/\s//g;
   $line =~ s/[A-Z]|[a-z]//g;
   $actual_IP = $line;

close (IFCONFIG);

# Find out how long it has been since we updated dyndns.
$age = find_age($last_day,$last_month,$last_year);

# Update dyndns and out config file if necessary.
if ( ($dns_IP != $actual_IP) || ( $age = 25 ) )
{
   print STDOUT "Updating Dynamic DNS from: $age days ago, Address: $dns_IP to 
$actual_IP \n";
   # update dyndns ip address
   open(OUPUT,"$command |") || die "Unable to execute ddns.\n";
  #@output = OUTPUT;
  #print "@output\n"; 
   close (OUTPUT);

   # update date in conf file
   ($sec, $min, $hour, $now_dd, $now_mm, $now_, $wday, $yday, $isdst) = localtime;
   $now_ += 1900;
   $now_mm++;
   open (OUTPUT, "$config") || die "Unable to open $config for writing.\n";
  print OUTPUT "DATE=$now_dd/$now_mm/$now_\n";
   close (OUTPUT);

}
else { print STDOUT "Dynamic DNS OK\n"; }


#  Subroutine to grab $mm and $dd and calculate the number of days since the last 
update 
sub find_age 
{
   $ = @_[2];
   $mm = @_[1]; 
   $dd = @_[0]; 

   # Get the current date.
   ($sec, $min, $hour, $now_dd, $now_mm, $now_, $wday, $yday, $isdst) = localtime;
   $now_mm++;
   $now_ += 1900;

   $find_age=0;
   $find_age=$find_age + $now_dd - $dd;

   if (($now_mm  $mm || ($now_mm == $mm  ($now_dd - $dd) = 0))  (int($find_age + 
0.5 + ($now_mm - $mm) * 30.41667) = 365)  $now_) * 12) + $now_mm) - 
((($) * 12) + $mm))  12) { $find_age = int($find_age + 0.5 + ($now_mm - $mm) * 
30.41667); } #less than a year
   else { $find_age = int($find_age + 0.5 + ($now_mm + (($now_ - $) * 12) - 
$mm) * 30.41667); }
   if ($mm == 2$now_mm != 2) { $find_age = $find_age - 2; } #month of February

   return $find_age;
} 




DATE=31/7/2000