On 7/26/06, David Looney <[EMAIL PROTECTED]> wrote:
Lan Barnes wrote:
> Some time ago I asked about how to send myself email when Cox changes my
> IP address. With help from the list, I came up with this, which works
> through testing (but hasn't yet been tested by Cox).
>
[snip - script to connection to whatismyip.com & parse html response,
compare with old IP, etc]
What I do is to use traceroute to get my home router to cough up it's
IP address (which is my external IP, of course), something like:
#!/bin/sh
# Old address saved in file
oldip=`cat ~/.ipaddress`
# Get your default routers inet address
export inetip=`/usr/sbin/traceroute -n -m1 smtp.west.cox.net |
/usr/bin/sed -e "/traceroute/d" | /usr/bin/awk '{print $2}'
if ! [ $oldip -eq $inetip ] ; then
echo $inetip > ~/.ipaddress
echo "New IP address : "$inetip
echo "IP changed - "$inetip | mail -s "New IP" [EMAIL PROTECTED]
fi
As always, YMMV. The advantage is that it doesn't rely on an external
website or connectivity except to the router.
OK, how about this one:
$ /usr/sbin/traceroute -n -m1 2>/dev/null $(gawk '/nameserver/{print
$2; exit}' /etc/resolv.conf) | gawk '{print $2}'
This reads the IP address from the first line labeled "nameserver" in
/etc/resolv.conf, then does a traceroute to it. That way I don't have
to know the name of my nameserver. Of course this doesn't work if the
DHCP server in your home router believes that it too is a nameserver.
Works for me with RoadRunner and Netgear router and FC3.
Note that the 2>/dev/null does what /usr/bin/sed -e "/traceroute/d"
was intended to do in Dave Looney's script. But in fact that
undesired line from traceroute is sent to stderr not stdout.
carl
--
carl lowenstein marine physical lab u.c. san diego
[EMAIL PROTECTED]
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list