How to obtain current IP address?



Here's the situation:

A machine is connected to the net via dynamic IP address.

Periodically, I want that machine to check it's current IP#, and if it has changed, to notify me (how it does that is not important.) (Yet)

So, how do you find out your current IP# via Tcl?

The following is my first kick at the can. Using example code from Brent Welch's "Practical Programming in Tcl and Tk", it:

-	uses the http package to fetch www.whatismyip.com

-	parses the page to extract the IP#

When the laughter dies down I would be very interested in any more elegant approaches anyone would like to suggest.

Thank's in advance.

Bob Halpin



--------------- Source -----------------
(Please excuse any ugly line-wrapping)

package require http;

proc extract_ip {Src} {
foreach Line [split $Src \n] {
if {[string first "<TITLE>Your IP" $Line]<0} {continue;}
if {[regexp {([0-9]*)(\.)([0-9]*)(\.)([0-9]*)(\.)([0-9]*)} $Line match Ip1 dot1 Ip2 dot2 Ip3 dot3 Ip4]} {
return "$Ip1.$Ip2.$Ip3.$Ip4";
}
}
return "";
}
proc httpCallback {token} {
upvar #0 $token state
set Result [extract_ip $state(body)];
http::cleanup $token;
set ::Ip $Result;
}
set ::Ip "";
http::geturl "http://www.whatismyip.com"; -command httpCallback;
vwait ::Ip;
puts "IP is: $::Ip";
return $::Ip;


-------------------------------------------------------
.