Re: Finding the external IP on a DSL router?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



#!/bin/bash
#
# 11-01 Pete Nesbitt
# script to check if eth0's IP has changed.
#

DATE=`/bin/date`

# set variables for email
EMAIL="user@xxxxxxxxxx user@xxxxxxxxxxxxxxx"

# a file to hold the previous IP
OLDIP="/usr/local/scripts/check_ip/oldip.txt"

# check for the current IP
CURRENT_IP="`/sbin/ifconfig -a|/bin/grep -A 2 eth0|/bin/awk '/inet/ { print $2 }'|/bin/sed -e s/addr://`"


# compare to new IP to last IP
if [ "`/bin/cat $OLDIP`" != "$CURRENT_IP" ]; then

# next part is all one line
/bin/echo "The IP was reset at $DATE (ea 20 min.). The OLD IP was `cat $OLDIP`. The New IP is $CURRENT_IP. You must update
yi.org and hostname."|/bin/mail -s "New IP Address" $EMAIL
# end if the long line


# copy the new IP to the old IP
  /bin/echo "$CURRENT_IP" > $OLDIP
fi

exit

Just a side note Pete - I'm by no means a scripter, but where does the above script find the router's external IP address?


What you said before holds true - if you set up dyndns or equivalent, you can ping the address to get the outside ip, but your script (to my untrained eyes), seem to grab the IP information from ifconfig.

If I run ifconfig -a, it shows a local address of my gateway as the inet address on eth0, and my outside address on ppp0.

But if he's using a router, would his gateway not be a local address?

You're probably right though, as I don't know much about these things, but I just want to make sure.

Regards,
Ed.


-- redhat-list mailing list unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux