Re: Need to monitor when IP Address changes
David Adam <[email protected]>
| Newsgroups | gmane.os.freebsd.newbies |
|---|---|
| Message-ID | <[email protected]> |
> 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="[email protected]" 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 [email protected] _______________________________________________ [email protected] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-newbies To unsubscribe, send any mail to "[email protected]"
scriptfile
(text/plain, 940 B)
#! /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 ([email protected]) ### CHANGE THESE VARIABLES! # Interface to watch IFACE="xl0" # File to use IPFILE="/var/tmp/ipfile" # Address to mail EADDRESS="[email protected]" # 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