Subject: Re: Can I determine my own IP in tcl? - DN [1]


"Bill Schongar" <bills@lcdmultimedia.com> - 10 Jan 2000 - comp.lang.tcl

 Carl Hooper wrote:

 >Seems like this should be very easy, but I can't find a way to do it.
 >I don't want to have to use a system call because I want it to be OS
 >independent.

 Someone else had posted a trick a while back, and it's
 worked quite well for me:

     # Some open port number
     set port "4321"

     # Create a temporary server that doesn't do anything
     set server [socket -server "#" $port]

     # Create a temporary client
     # - MUST use "info hostname" to ensure proper IP resolution
     set client [socket [info hostname] $port]

     # Get the first element (IP addr) of the socket's data
     # elements are: IP addr, full host path (foo.bar.com), port
     set IP [lindex [fconfigure $client -sockname] 0]

     # Shut 'em down
     close $client
     close $server

 Hope that helps..

 -Bill

Last modified
2000-01-21

(195.108.246.50)

Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated