Posted by Dave on

What’s my IP address?

Useful question, this is how I answer it on my windows systems.

I have now uploaded this to github,

Its a TCL/TK script that invokes the windows XP shell command ping.

As noted, I use an information graphic to decorate the box. This is not part of activestate’s tcl/tk distribution, and thus needs to be copied to $tklibrary/images. (See also Scripting on Windows, on this wiki.)

I am not happy with the triming of the ip address, which is displayed into the address variable using square brackets. Since these have a specific syntactical meaning, I can’t find the syntax to remove them from the string.

wm title . {Query site ip?}
wm iconname . {Query site ip?}
wm geometry . 225x65+500+100
# This is not part of the package, it needs to be copied here 
image create photo infopic -file [file join $tk_library images info.gif]

set pingreply {} 
# windows XP 
set pingreply [exec ping -n 1] 
set address [ lindex $pingreply 2 ] 
# only tested on one ip address, do I need to subtract two from length 
# to remove the first and last. What is the syntax to remove leading and 
# trailing []. 

set daddress [string range $address 1 [expr [ string length $address ] - 2]]
set messagetext " public tcp/ip no : $daddress" 
set buttontext " Done "

frame .top 
frame .bottom

label .top.icon -image infopic 
frame .top.f -width 50 label .top.f.mess -text $messagetext

pack .top.f.mess -side top -fill x 
pack .top.icon .top.f -side left
button .bottom.dismiss -text $buttontext -command "exit" 
pack .bottom.dismiss pack .top .bottom

proc exit {} { destroy . }

The script can be downloaded

Chris advises that

set daddress [string trim $address {[]} ]

removes the brackets from the address and is obviously much neater and is character based. It implements a remove the unwanted character rule, not remove the first and last characters.

Comments ( 2 )

  1. What’s my tcp/ip address? | Well Red
    [...] allocated tcp/ip address on the screen of one of my windows desktops. Full details are at What’s my IP Address on the wiki. Vive le command line! I used TCL/TK and the command line [...]
  2. ReplyAuthorDave
    I uploaded this to github today

This site uses Akismet to reduce spam. Learn how your comment data is processed.