I wanted to do something similar so I wrote these 2 little scripts to solve
my problem of occasional IP address changes.

I have 2 parts.
The first script gets the current address and stuffs it into a temp file.
The second gets the current address and then compairs it to the stored
address, if different I get an email.
both these scritps run on a Cron.


Part one (stuffs the current address into temp file)

# Get IP address from interface
IPADDR=`ip addr show eth0 | grep "inet " | sed s/"    "// | cut -d' ' -f 2 |
cut -d'/' -f1`
#write address to tmp for later comparison
echo $IPADDR > /tmp/ip.txt

Part 2 mails the new address to me if it has changed.

#Mail ip address
#!/bin/sh
# file = mailip 12/11/02
su_user=root
prefix=/tmp/$su_usr.$$
# Get current IP address from interface
IPADDR=`ip addr show eth0 | grep "inet " | sed s/"    "// | cut -d' ' -f 2 |
cut -d'/' -f1`
#
{ su $su_usr -c "$cmd"
} 2>$prefix.err 1>$prefix.out

{
        echo "    ">>$prefix.msg
        echo "My IP address is : "$IPADDR >> $prefix.msg
        echo "    ">>$prefix.msg
} > $prefix.msg

# send the mail
# compaire old and new addresses
OLD_IPADDR=`cat /tmp/ip.txt`

if [ $OLD_IPADDR = $IPADDR ]
 then
 echo "whoo hoo" # skip (or do something) if same
else
 mail -s "Internet IP address Changed!" [EMAIL PROTECTED] < $prefix.msg
fi
#
# clean up
rm $prefix*
#
# written by
# vette66 (chuck)
# http://www.vette66.com

----- Original Message -----
From: "Erich Titl" <[EMAIL PROTECTED]>
To: "Brad Klinghagen" <[EMAIL PROTECTED]>; "LEAF User"
<[EMAIL PROTECTED]>
Sent: Sunday, May 23, 2004 6:03 AM
Subject: Re: [leaf-user] Simple IP address retrieval question


Brad

At 06:12 23.05.2004, Brad Klinghagen wrote:
>Currently I have an ISP that provides an IP address via DHCP, and the
>address occasionally changes. What I want to do is to retrieve the IP
>address of the Internet side interface (eth0) of my firewall without
>manual intervention, and stuff that value into a variable. I need the
>value for additional DNAT rules because I have a web server and email
>server on my LAN.
>
>This sounds like it should have a really simple solution (like some Bash
>command or something), and I've looked all over to find how to do this,
>but haven't seen it anywhere, so forgive me for my ignorance if I've
>overlooked something outrageously simple.

Most DHCP clients provide some sort of exit hooks, where the user can, at
his discretion, do whatever he wants with the newly provided values. For
dhclient this is /etc/dhclient-exit-hooks, dhcpcd uses dhcpcd.exe by
default in /etc/dhcpd, for pump I have no info.

HTH

Erich


THINK
Püntenstrasse 39
8143 Stallikon
mailto:[EMAIL PROTECTED]
PGP Fingerprint: BC9A 25BC 3954 3BC8 C024 8D8A B7D4 FF9D 05B8 0A16




-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id149&alloc_id66&op=ick
------------------------------------------------------------------------
leaf-user mailing list: [EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-user
SR FAQ: http://leaf-project.org/pub/doc/docmanager/docid_1891.html



-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id149&alloc_id66&op=click
------------------------------------------------------------------------
leaf-user mailing list: [EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-user
SR FAQ: http://leaf-project.org/pub/doc/docmanager/docid_1891.html

Reply via email to