Date: Fri, 14 Jan 2005 14:03:31 +0800 (WST) From: David Adam <zanchey@ucc.gu.uwa.edu.au> To: Brian John <brianjohn@fusemail.com> Cc: merv <merv@merv.org.uk> Subject: Re: Need to monitor when IP Address changes Message-ID: <Pine.LNX.4.58.0501140856100.12638@mussel.ucc.gu.uwa.edu.au> In-Reply-To: <3296.209.87.176.132.1105652323.fusewebmail-19592@www.fusemail.com> References: <41E5C873.4030401@fusemail.com> <200501130821.52869.merv@merv.org.uk> <3296.209.87.176.132.1105652323.fusewebmail-19592@www.fusemail.com>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --]
> That's awesome. Very simple. Now how could I have it figure out if the
> IP address has actually changed? I only want it to email me if it
> changes. Sorry, I'm very fluent in Windows but have only been using
> FreeBSD for a couple of days.
Hi Brian,
Although you're getting a lot of people telling you to go with the dyndns,
I think that you're probably doing the right thing from a simplicity point
of view. I had no end of trouble getting the No-IP client running under
FreeBSD (although that may have a lot to do with the crappiness of my
ISP, and their bizarre cable login program).
I think what you want to do is schedule a cronjob (like a Scheduled Task
or at command on Windows) to run a script that looks something like the
attached.
Make sure you change the variables at the top:
Change the line that says IFACE="xl0" to set the interface you are
watching.
Change the line that says IPFILE="/var/tmp/ipfile" to something that the
user you are running cron as will have access to (should be ok there).
Change the line that says EADDRESS="zanchey@ucc.gu.uwa.edu.au" to use your
e-mail address. I don't want your IP updates :-)
If you need help learning how to schedule a cron job, ping the list again
and one of us should be able to help out.
(Incidentally, this won't run on 4.x, as it requires the -m option to grep
in order to avoid choking on interfaces with more than one IP. I'm sure
there's a way around this using awk or something.)
HTH,
David Adam
zanchey@ucc.gu.uwa.edu.au
[-- Attachment #2 --]
#! /bin/sh
###
# Script to watch for IP address changes and mail when they happen
# Will perform... um, unpredictably, with multiple IP addresses per interface
# Written January 2005 by David Adam (zanchey@ucc.gu.uwa.edu.au)
### CHANGE THESE VARIABLES!
# Interface to watch
IFACE="xl0"
# File to use
IPFILE="/var/tmp/ipfile"
# Address to mail
EADDRESS="zanchey@ucc.gu.uwa.edu.au"
# Get current IP
CURRENT_IP=$(ifconfig $IFACE |grep -m 1 "inet " |awk '{print $2}' )
if [ ! -f $IPFILE ]; then
touch $IPFILE
echo $CURRENT_IP > $IPFILE
fi
# Get previous IP
PREVIOUS_IP=$(cat $IPFILE)
#echo "Previous IP was $PREVIOUS_IP"
if [ "$CURRENT_IP" != "$PREVIOUS_IP" ]; then
# echo "IPs are different!"
# echo "Current IP is $CURRENT_IP"
mail -s "IP Change: $CURRENT_IP" $EADDRESS << EOM
The IP of your system has changed from $PREVIOUS_IP to $CURRENT_IP.
EOM
fi
echo "$CURRENT_IP" > $IPFILE
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.LNX.4.58.0501140856100.12638>
