This script will send the current external IP of the sending machine to a given email address. To use it, call ::mailip::sendip [email protected].
It assumes, that you have a running SMTP sever on your connected machine.
# mailip.tcl # package require http package require tdom package require smtp namespace eval mailip { # Setup here... variable SMTPSERVER localhost variable SENDER [email protected] ;# We need a valid sender address } proc ::mailip::getip {} { # Returns your current external IP # or 0.0.0.0 # set result 0.0.0.0 set request [::http::geturl http://checkip.dyndns.org] set answer [::http::data $request] set adom [::dom parse -html $answer] set domdoc [$adom documentElement] set body [[lindex [$domdoc getElementsByTagName body] 0] text] set result [string trim [lindex [split $body :] 1]] return $result } proc ::mailip::sendip {to} { set msg [::mime::initialize -canonical text/plain -string "Your IP: [::mailip::getip]"] ::smtp::sendmessage $msg \ -header [list Subject "IP-Service"] \ -header [list From "$::mailip::SENDER"] \ -header [list To "$to"] \ -servers $::mailip::SMTPSERVER ::mime::finalize $msg } package provide mailip 0.1
tb: I added a valid sender to the namespace variables. It's needed, to let the Smarthost accept the outgoing email.