Ping Multiple Addresses Using TCL Script Part 1

There might be situation where you might need to ping multiple IP addresses to check the full connectivity between devices.

This tutorial shows you exactly how to do that using TCL script.
I’ll be explaining how it works in details so you don’t need to have any programming or scripting experience.

TCL Script

Below is the sample script TCL script to ping multiple IP addresses.

foreach ip {
192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4
192.168.1.5
192.168.1.6
192.168.1.7
192.168.1.8
192.168.1.9
192.168.1.10
} { ping $ip }

What the above script is doing is that, when foreach loop is run for the first time, it populates the variable $ip with first IP address (192.168.1.1). The second time the loop runs, $ip becomes 192.168.1.2.

The loop will keep running until it reaches the last ip address (i.e 192.168.1.10)
The last part of the script would be { ping $ip }. This will ping the IP address by substituting variable $ip with the listed values one at a time. As the loop have 10 IP addresses, the ping command will run 10 times with different IP addresses.

Executing the Script

First get into TCL scripting shell/mode

Router>enable
Router#tclsh
Router(tcl)#

Copy the above TCL script.

Router(tcl)#foreach ip {
+>192.168.1.1
+>192.168.1.2
+>192.168.1.3
+>192.168.1.4
+>192.168.1.5
+>192.168.1.6
+>192.168.1.7
+>192.168.1.8
+>192.168.1.9
+>192.168.1.10
+>} { ping $ip re 5 }

If you press enter, the script will be executed. The following is the output of the above script

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/4 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/4 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.4, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/4 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.5, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/4 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.6, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/4 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.7, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/4 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.8, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.9, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/4 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.10, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/4 ms

This tutorial showed very basic TCL script. You can modify or tweak this script to do lot of things, like pinging the whole subnets, etc.
Check out the Part 2 of this tutorial

3 thoughts on “Ping Multiple Addresses Using TCL Script Part 1”

Comments are closed.