There are times that we want to check the connectivity of all the systems on our subnet - to see which machines are present, and which are not. Pinging them one at a time is a bit slow, but pinging them all at once in a simple script sets up too many connections and the script is likely to fall over. Then how do you display the results quickly and easily?
I have updated an "old favourite" script -
"tkpingle" which check out a series of systems named on the command line - to test a complete subnet. Systems are "ping"ed 16 at a time, and layed out in a grid rather than a single column

Here's the initial display - with systems xxx.xxx.xxx.0 and xxx.xxx.xxx.255 greyed out as these are special "broadcast" addresses and not to be assigned to any system.

During operation, systems are tested out column by column. All systems still to be tested are shown in salmon, with systems going red as their test starts, then changing to orange, yellow and finally white if they respond to three pings. Note that the "run" button is disabled while the test is running.

When the testing is completed, the "run" button is re-enabled and the status report updated to show that the tests are complete. And I've turned the status report to yellow so that it's very clear to the user that the tests are completed.
The complete script is
[here]
Some elements worthy of comment (even for people who have used a bit of Tk and expect before ...
*
Making a grid uniform
The following - applied to one label in each row and each column - ensures that all cells are going to be of the same width and height.
grid rowconfigure . .la_$syslab -weight 1 -uniform w
grid columnconfigure . .la_$syslab -weight 1 -uniform w
*
Closing out complete or incomplete pings
Spawning processes uses up system resources that need to be released if there's further resources needed (if there wasn't anything further to do, we could get away without doing this as the script will clean up on exit).
The use of
catch is to avoid crashing the script if the script had closed the resource already, and the
wait is to ensure that the resource truely is closed.
foreach done $tidy {
if { [catch {close -i $done} msg ] } {
# ignore
} else {
wait -i $done
}
}
*
Spawning parallel processes A
Processes that are
spawned set their ID in the global variable
$spawn_id. We save all the spawn_ids away so that we can check how all the processes are running in parallel later on.
for {set k 0} {$k < 16} {incr k} {
set val [expr $k + $j * 16]
set system "$subnet.$val"
spawn ping -c 3 $system
set id($system) $spawn_id
*
Modal buttons
In order to avoid a second series of test being started while the previous set is still running, we disable the "run" button as soon as its been pressed ...
.redo config -state disabled
... and we re-enable it just as it finished its work.
.redo config -state normal
(written 2011-09-18)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
T242 - Tcl/Tk - More on Expect [435] Expect for Windows - (2005-09-04)
[1173] Cheat Sheet / Check list for Expect maintainers - (2007-05-02)
[1411] Buffering of inputs to expect, and match order - (2007-10-27)
[1475] Tcl/Tk - updating your display while tasks are running - (2007-12-16)
[1531] Expecting a item from a list of possibles - (2008-02-04)
[2475] Quick easy and dangerous - automated logins via Tcl / Expect - (2009-10-24)
[3009] Expect in Perl - a short explanation and a practical example - (2010-10-22)
T212 - Tcl/Tk - Expect Processes [287] Checking that all our servers are up and accessible - (2005-04-22)
[675] Adding PHP tags to an old cgi program - (2006-04-08)
[1785] What is running on your network? (tcl and expect) - (2008-09-04)
[2474] Using Tcl and Expect to automate repetitive jobs - (2009-10-24)
[2489] Parallel Pinging, using Python Threads or Expect spawn lists - (2009-11-02)
[4678] Expect with Ruby - a training example to get you started - (2016-05-18)
A163 - Web Application Deployment - Network Configuration and Security [11] A bolt of lightning on Multicasting - (2004-08-11)
[37] Security and Safety - (2004-09-03)
[267] Searching security holes - (2005-04-04)
[332] Looking up IP addresses - (2005-06-01)
[506] What are DHCP and DNS? - (2005-11-27)
[511] Domain Forwarding - 2 ways of doing it - (2005-11-29)
[1073] Heartbeat script in Perl - (2007-02-09)
[1408] Wireless hotel tips - FTP and Skype connections failing - (2007-10-26)
[1666] Slow boot and terminal start on Linux boxes - (2008-06-05)
[1712] As different as night and tyres - (2008-07-18)
[1904] Ruby, Perl, Linux, MySQL - some training notes - (2008-11-23)
[2052] How was my web site compromised? - (2009-02-24)
[4134] Setting up your MacBook Air as a mobile broadband router - (2013-07-07)
Some other Articles
Which or ATOC - who reads train fares right?Why would you want to use a Perl hash?A threat in the post? Poor marketing practise from Smiletrain?Apache Internal Dummy Connection - what is it and what should I do with it?Checking all the systems on a subnet, using Expect and TkNeedle in a haystack - finding the web server overloadAwk v PerlPerl and CGI - simple form, and monitoring script.Take the dog on a lead - do not carry her. Perl references.Getting more log information from the Apache http web server