Cover V06, I01
Article
Figure 1
Figure 2
Listing 1
Listing 2

jan97.tar


Listing 2: NS script

#!/usr/bin/wish -f

# -----------------------------------------
# NS -- netstat output viewer
# -----------------------------------------

lappend auto_path "/usr/local/lib/tkextra"

# ------------------------------
# Application-specific globals
# ------------------------------

# options for the 'netstat' command, set by menu items, initially off
set f_family " "
set n_addr " "
set P_proto " "
set verbose " "

# ------------------------------
# Application-specific routines
# ------------------------------

#
# Do a "netstat", collect the output, put into a list-box
#
proc get_stat {opt} {
global f_family n_addr P_proto verbose

#
# Generate the command line
# (use "col -x" to expand the tabs in the 'statistics' output)
#
set cmd "|netstat $verbose $f_family $n_addr $P_proto $opt | col -x"

#
# Let the user know that this might take awhile
# Put a message heading at the top of the scroll box
# Reposition the scroll box so the top line shows
# Refresh everything before running the command
#
.ps.list delete 0 end
.ps.list insert 0 "Please wait, getting information..."
.ps.list yview 0
update

#
# Execute the command line
# Collect the resulting list of lines
# Fill the list-box with the lines
#
fill_list  .ps.list  [read_list $cmd] 0
}


# ------------------------------
# GUI Specific Routines
# ------------------------------

#
# Make the main control panel -- fill it with some controls
#
proc make_control_panel { } {
global f_family P_proto n_addr verbose

#
# Setup some window-manager options
#
wm title    . "NetStat"
wm iconname . "NS"
wm command  . "NetStat"

#
# Make the menu-bar, all the menus, and the menu-items
#
menu_bar .mbar 0   \
{menu File}   \
{cmd  Quit exit}  \
{end left}   \
{menu Options}  \
{check "Numeric Addrs" n_addr  " " "-n"} \
{check "Verbose" verbose  " " "-v"} \
{end left}      \
{menu Family}      \
{radio All  f_family " "}  \
{sep}       \
{radio INET  f_family "-f inet"} \
{radio UNIX  f_family "-f unix"} \
{end left}     \
{menu Protocol}    \
{radio All  P_proto " "}  \
{sep}      \
{radio UDP  P_proto "-P udp"} \
{radio TCP  P_proto "-P tcp"} \
{radio IP  P_proto "-P ip"} \
{radio ICMP  P_proto "-P icmp"} \
{radio GCMP  P_proto "-P gcmp"} \
{end left}

#
# Make the scrolling list-box (resize it from the default 80x5)
#
mk_list  .ps ""
# For Tk3.6 .ps.list configure -geometry 80x12
.ps.list configure -height 12

#
# Make the control buttons
#
buttons .cmd "" left 0     \
{width 4}     \
{cmd Netstat    "get_stat \"\""} \
{cmd MultiCast  "get_stat -g"}  \
{cmd "TCP Infc" "get_stat -i"}  \
{cmd Streams    "get_stat -m"}  \
{cmd ARP        "get_stat -p"}  \
{cmd Routes     "get_stat -r"}  \
{cmd Stats      "get_stat -s"}  \
{cmd Quit  exit }

# pack menu   -> top
# pack btns   -> on the bottom
# pack scroll-box -> in the middle

pack .mbar  -side top    -fill x
pack .ps    -side top    -fill both -expand yes
pack .cmd   -side bottom -fill x
}


# ------------------------------
# M A I N - L I N E
# ------------------------------

#
# Create the GUI
# Fill the scroll-box
#
make_control_panel
get_stat ""

# ------------------------------
# The End.
# ------------------------------