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).

Not a daemon, really. I use cron to run it every 10 minutes.

Enjoy,


************************
#!/usr/bin/tclsh
# use wget to get the ip addr
catch {exec wget http://whatismyip.com}

#parse resulting index.html that wget saves
set IDX [open ./index.html r]
set indexContents [read $IDX]
close $IDX
# delete it before the next use
file delete -force ./index.html

set iCLst [split $indexContents "\n"]
foreach ln $iCLst {
        if {[regexp {displaycopy..(\d+\.\d+\.\d+\.\d+)} $ln match ipadr]} {
                break
        }
}

#compare with saved last IP addr
if {[file exists ./old_ip.txt]} {
        set FIL [open old_ip.txt r]
        set ipContents [read $FIL]
        close $FIL
        regexp {(\d+\.\d+\.\d+\.\d+)} $ipContents match oldipadr
        if {"$oldipadr" eq "$ipadr"} {
                exit
        }
}

#if changed, fix old file storing it
file delete -force ./old_ip.txt
set FIL [open old_ip.txt w]
puts $FIL $ipadr
close $FIL

#if changed, send mail to selected addresses

set toAddr "[EMAIL PROTECTED],[EMAIL PROTECTED]"

exec echo "Your new IP address is $ipadr" | mail -s "Cox has crossed you up 
again" $toAddr

-- 
Lan Barnes
Linux Guy, SCM Specialist     
Tcl/Tk Enthusiast 

Will future presidential candidates debate the ontological status
of Schrödinger's cat?
    - Dennis Overbye on NASA political appointee inserting "theory" into 
      Big Bang text


-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to