Re: script to update dyndns IP

2010-03-19 Thread Aaron Stellman
On Thu, Mar 18, 2010 at 09:52:28PM -0400, Brad Tilley wrote:
 There are ports that do this with more features, but I thought others
 might like to do it in base with no added software. I've been using this
 script since 4.2 and it works OK:

since when is net/curl in base?



Re: script to update dyndns IP

2010-03-19 Thread Duncan Patton a Campbell
On Thu, 18 Mar 2010 21:52:28 -0400
Brad Tilley b...@16systems.com wrote:

 There are ports that do this with more features, but I thought others
 might like to do it in base with no added software. I've been using this
 script since 4.2 and it works OK:
 
 #!/bin/ksh
 
 # Cron this script to run every X minutes. Written for OpenBSD.
 
 # Get Current IP
 lynx -dump http://checkip.dyndns.org:8245/ | awk '{print $4}' | sed
 '/^$/d'  ip_new.txt
 
 # compare new with old
 diff ip_new.txt ip_old.txt
 
 # if different, send update
 if [ $? -ne 0 ]
 then
   #echo The IP has changed
   ip=$(cat ip_new.txt)
   # Following two lines are optional. Log date of change and IP history.
   date  ip_date.txt
   cat ip_old.txt  ip_history.txt
   curl --insecure
   
 https://user:p...@members.dyndns.org/nic/update?hostname=host.xxxmyip=$ipwildcard=NOCHGmx=NOCHGbackmx=NOCHG;
 fi
 
 # Whether a change has occurred or not, overwrite old with new
 cp ip_new.txt ip_old.txt
 

I've done a similar thing by hacking /sbin/dhclient-script to hook
out from add_new_address().  I also suppress add_new_resolv_conf()
and reupping from /etc/resolv.conf.save found in the main section.
Suppressing update of resolv.conf is optional but it's useful
to have the dns pointed at the nameserver for the domain and
just leave it there.

The hook out has to then call nsupdate with the newip address.  
The advantage to this approach is that is driven off the event
of a new address by dhcp and not by polling.  

Dhu



Re: script to update dyndns IP

2010-03-19 Thread Vadim Zhukov
On 19 March 2010 c. 10:54:26 Duncan Patton a Campbell wrote:
 On Thu, 18 Mar 2010 21:52:28 -0400

 Brad Tilley b...@16systems.com wrote:
  There are ports that do this with more features, but I thought
  others might like to do it in base with no added software. I've been
  using this script since 4.2 and it works OK:
 
  #!/bin/ksh
 
  # Cron this script to run every X minutes. Written for OpenBSD.
 
  # Get Current IP
  lynx -dump http://checkip.dyndns.org:8245/ | awk '{print $4}' | sed
  '/^$/d'  ip_new.txt
 
  # compare new with old
  diff ip_new.txt ip_old.txt
 
  # if different, send update
  if [ $? -ne 0 ]
  then
#echo The IP has changed
ip=$(cat ip_new.txt)
# Following two lines are optional. Log date of change and IP
  history. date  ip_date.txt
cat ip_old.txt  ip_history.txt
curl --insecure
 
  https://user:p...@members.dyndns.org/nic/update?hostname=host.xxxm
 yip=$ipwildcard=NOCHGmx=NOCHGbackmx=NOCHG fi
 
  # Whether a change has occurred or not, overwrite old with new
  cp ip_new.txt ip_old.txt

 I've done a similar thing by hacking /sbin/dhclient-script to hook
 out from add_new_address().  I also suppress add_new_resolv_conf()
 and reupping from /etc/resolv.conf.save found in the main section.
 Suppressing update of resolv.conf is optional but it's useful
 to have the dns pointed at the nameserver for the domain and
 just leave it there.

 The hook out has to then call nsupdate with the newip address.
 The advantage to this approach is that is driven off the event
 of a new address by dhcp and not by polling.

Possibly you could use dhclient.conf instead?

--
  Best wishes,
Vadim Zhukov

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?



Re: script to update dyndns IP

2010-03-19 Thread Brad Tilley
On Fri, 19 Mar 2010 00:20 -0700, Aaron Stellman z...@x96.org wrote:
 On Thu, Mar 18, 2010 at 09:52:28PM -0400, Brad Tilley wrote:
  There are ports that do this with more features, but I thought others
  might like to do it in base with no added software. I've been using this
  script since 4.2 and it works OK:
 
 since when is net/curl in base?

It's not. My mistake. Thanks to some suggestions off-list on using lynx
rather than curl, this seems to work OK:


#!/bin/ksh

# Cron this script to run every X minutes. Written for OpenBSD base.
# set FORCE_SSL_PROMPT:yes in /etc/lynx.cfg

user=test
pass=test
host=test.dyndns.org

# Get Current IP
lynx -dump http://checkip.dyndns.org:8245/ | awk '{print $4}' | sed
'/^$/d'  ip_new.txt

# Compare new with old.
diff ip_new.txt ip_old.txt

# If different, send update.
if [ $? -ne 0 ]
then
  ip=$(cat ip_new.txt)
  # Following two lines are optional. Log date of change and IP history.
  date  ip_date.txt
  cat ip_old.txt  ip_history.txt
  lynx -dump -auth=${user}:${pass}
  https://members.dyndns.org/nic/update?hostname=${host}myip=${ip};
fi

# Whether a change has occurred or not, overwrite old with new
cp -f ip_new.txt ip_old.txt



Re: script to update dyndns IP

2010-03-19 Thread Duncan Patton a Campbell
On Fri, 19 Mar 2010 14:04:16 +0300
Vadim Zhukov persg...@gmail.com wrote:

 On 19 March 2010 c. 10:54:26 Duncan Patton a Campbell wrote:
  On Thu, 18 Mar 2010 21:52:28 -0400
 
  Brad Tilley b...@16systems.com wrote:
   There are ports that do this with more features, but I thought
   others might like to do it in base with no added software. I've been
   using this script since 4.2 and it works OK:
  
   #!/bin/ksh
  
   # Cron this script to run every X minutes. Written for OpenBSD.
  
   # Get Current IP
   lynx -dump http://checkip.dyndns.org:8245/ | awk '{print $4}' | sed
   '/^$/d'  ip_new.txt
  
   # compare new with old
   diff ip_new.txt ip_old.txt
  
   # if different, send update
   if [ $? -ne 0 ]
   then
 #echo The IP has changed
 ip=$(cat ip_new.txt)
 # Following two lines are optional. Log date of change and IP
   history. date  ip_date.txt
 cat ip_old.txt  ip_history.txt
 curl --insecure
  
   https://user:p...@members.dyndns.org/nic/update?hostname=host.xxxm
  yip=$ipwildcard=NOCHGmx=NOCHGbackmx=NOCHG fi
  
   # Whether a change has occurred or not, overwrite old with new
   cp ip_new.txt ip_old.txt
 
  I've done a similar thing by hacking /sbin/dhclient-script to hook
  out from add_new_address().  I also suppress add_new_resolv_conf()
  and reupping from /etc/resolv.conf.save found in the main section.
  Suppressing update of resolv.conf is optional but it's useful
  to have the dns pointed at the nameserver for the domain and
  just leave it there.
 
  The hook out has to then call nsupdate with the newip address.
  The advantage to this approach is that is driven off the event
  of a new address by dhcp and not by polling.
 
 Possibly you could use dhclient.conf instead?
 

Yes, that's prob'ly the case.  Sometime tho' an outright hack that doesn't
get lost in configuration semantics is the best way to test out an idea,
and that's all this was.  This is actually using a generic hack that lets
me impose prolog semantics on the event of address reassignment.

Dhu

 --
   Best wishes,
 Vadim Zhukov
 
 A: Because it messes up the order in which people normally read text.
 Q: Why is top-posting such a bad thing?
 A: Top-posting.
 Q: What is the most annoying thing in e-mail?



Re: script to update dyndns IP

2010-03-19 Thread Corey

On 03/18/2010 08:52 PM, Brad Tilley wrote:

There are ports that do this with more features, but I thought others
might like to do it in base with no added software. I've been using this
script since 4.2 and it works OK:

#!/bin/ksh

# Cron this script to run every X minutes. Written for OpenBSD.

# Get Current IP
lynx -dump http://checkip.dyndns.org:8245/ | awk '{print $4}' | sed
'/^$/d'  ip_new.txt

# compare new with old
diff ip_new.txt ip_old.txt

# if different, send update
if [ $? -ne 0 ]
then
   #echo The IP has changed
   ip=$(cat ip_new.txt)
   # Following two lines are optional. Log date of change and IP history.
   date  ip_date.txt
   cat ip_old.txt  ip_history.txt
   curl --insecure
   
https://user:p...@members.dyndns.org/nic/update?hostname=host.xxxmyip=$ipwildcard=NOCHGmx=NOCHGbackmx=NOCHG;
fi

# Whether a change has occurred or not, overwrite old with new
cp ip_new.txt ip_old.txt

   
Did you ever have a problem with not updating in a certain period of 
time, and DynDNS expiring your account?  I did, probably because I have 
one of the free accounts, and I had to add code to my own updater script 
to account for that (i.e., send an update every 30 days whether my IP 
had changed or not).


Mine runs hourly out of cron, too.  I tried invoking it from 
dhclient-script, but never could get it to work reliably, and I didn't 
want to hack dhclient-script itself.  I maybe ought to have another look 
at that, though -- some things probably have changed there since the 
last time I tried.


Corey

P.S. Here's mine, if anyone's interested.

#!/bin/sh
# Update dyndns.com record if IP address changed (run on bootup and
# out of cron)

#set -x

INTFC=vr0
INFO=/var/run/dyndns-update.dat
MAX_INTERVAL=30 #days

function log {
   # Log activity to syslog (daemon facility)
   logger -p daemon.info -t ddns-update $*
}

function dns-update {
   # dyndns.org update site
   url='http://members.dyndns.org/nic/update?'
   url=${url}'system=dyndnshostname=clingo.dyndns.org'
   url=${url}myip=$1
   log Server response: `lynx -dump -auth user:pass $url`
}


# Main program
today=`date '+%j'`

# Get current external IP address. If it's not set, don't update.
current_ip=`ifconfig $INTFC | awk '/inet / { print $2 }' | \
   grep -v '192.168.1'`
if [ -z $current_ip ]; then
   log No IP address for $INTFC, exiting
   exit 1
fi

# Get last run's IP and day from file.  If there's no file, don't update,
# but try to create one for next time
if [ -r $INFO ]; then
   last_ip=`cat $INFO | awk '{ print $1 }'`
   last_day=`cat $INFO | awk '{ print $2 }'`
else
   log Data file $INFO not found, exiting
   echo $current_ip $today  $INFO
   exit 2
fi
# Write this run's data to file
echo $current_ip $today  $INFO

# If current IP does not match last IP, then update
if [ $current_ip != $last_ip ]; then
   log IP changed to $current_ip, updating
   dns-update $current_ip
   exit 0
else
   msg=No change in IP, exiting # and see if time triggers an update
fi

# If it has been more than xx days since last update, force one. They
# act like if the address hasn't changed it's abuse, yet I get emails
# every so often wanting me to confirm continued activity
if [ ! -z $last_day ]; then
   interval=$(( $today - $last_day ))
else
   interval=0
fi

[ $interval -lt 0 ]  interval=$(( $interval + 366 )) # year rollover
if [ $interval -gt $MAX_INTERVAL ]; then
   log More than $MAX_INTERVAL days since last update, updating
   dns-update $current_ip
   exit 0
fi

# fallthru from above
log $msg

exit 0



script to update dyndns IP

2010-03-18 Thread Brad Tilley
There are ports that do this with more features, but I thought others
might like to do it in base with no added software. I've been using this
script since 4.2 and it works OK:

#!/bin/ksh

# Cron this script to run every X minutes. Written for OpenBSD.

# Get Current IP
lynx -dump http://checkip.dyndns.org:8245/ | awk '{print $4}' | sed
'/^$/d'  ip_new.txt

# compare new with old
diff ip_new.txt ip_old.txt

# if different, send update
if [ $? -ne 0 ]
then
  #echo The IP has changed
  ip=$(cat ip_new.txt)
  # Following two lines are optional. Log date of change and IP history.
  date  ip_date.txt
  cat ip_old.txt  ip_history.txt
  curl --insecure
  
https://user:p...@members.dyndns.org/nic/update?hostname=host.xxxmyip=$ipwildcard=NOCHGmx=NOCHGbackmx=NOCHG;
fi

# Whether a change has occurred or not, overwrite old with new
cp ip_new.txt ip_old.txt



Re: script to update dyndns IP

2010-03-18 Thread Brad Tilley
On Thu, 18 Mar 2010 21:52 -0400, Brad Tilley b...@16systems.com
wrote:
 There are ports that do this with more features, but I thought others
 might like to do it in base with no added software. I've been using this
 script since 4.2 and it works OK:
 
 #!/bin/ksh
 
 # Cron this script to run every X minutes. Written for OpenBSD.
 
 # Get Current IP
 lynx -dump http://checkip.dyndns.org:8245/ | awk '{print $4}' | sed
 '/^$/d'  ip_new.txt
 
 # compare new with old
 diff ip_new.txt ip_old.txt
 
 # if different, send update
 if [ $? -ne 0 ]
 then
   #echo The IP has changed
   ip=$(cat ip_new.txt)
   # Following two lines are optional. Log date of change and IP history.
   date  ip_date.txt
   cat ip_old.txt  ip_history.txt
   curl --insecure
   
 https://user:p...@members.dyndns.org/nic/update?hostname=host.xxxmyip=$ipwildcard=NOCHGmx=NOCHGbackmx=NOCHG;
 fi
 
 # Whether a change has occurred or not, overwrite old with new
 cp ip_new.txt ip_old.txt


I was under the impression that curl was in base. My mistake. It must
have pulled in as a dependency somewhere as I don't recall explicitly
installing it. I understand that lynx can be used to replace curl.

Brad