Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

local ip address

Status
Not open for further replies.

bvdang

Programmer
Aug 15, 2002
4
US
Does anybody know how I can obtain a local ip address using tcl command? I need to get the ip address in order to connect to MySQL database.

Thanks,
 
I tried this trick and it works:
Code:
  set port 3456
  set my_name nt2000fr
  socket -server ip_add $port
  proc ip_add {channel ip port} { puts $ip }
  close [socket $my_name $port]
Setting my_name to 'localhost' prints 127.0.0.1.

Can't you use 'localhost' or '127.0.0.1' as local IP address?

Good luck

ulis
 
A better solution to get a local IP address (don't need to choose a port # or give the host name):
Code:
 proc ip:adr {} {
     set me [socket -server xxx -myaddr [info hostname] 0]
     set ip [lindex [fconfigure $me -sockname] 0]
     close $me
     return $ip
 }
This come from
ulis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top