When you are studying for CCIE R&S you will have to check connectivity every now and then. It’s a good idea to use ping to check if you can reach all IP addresses of the routers and switches in your network. If you have many devices and many IP addresses it will take too much time to ping each IP address manually.
Luckily you can use TCLSH (Tool Control Language) on your Cisco routers and devices, a scripting language that is used a lot by Cisco and one of the things it can do is ping IP addresses for us.
First you should check the active IP addresses on your device using the following command:
Router#show ip alias
Address Type IP Address Port
Interface 192.168.12.1
Interface 192.168.13.1
Interface 192.168.1.1
The show ip alias command will show you all active IP addresses on your device. You can also use show ip interface brief | exclude unassigned to see all IP addresses of active interfaces:
Router#show ip interface brief | exclude unassigned
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 192.168.12.1 YES manual up up
Serial0/0.1 192.168.13.1 YES manual up up
Loopback0 192.168.1.1 YES manual up up
Copy and paste these to notepad…do this for all your routers and switches. Now we can use TCLSH to automatically ping all these IP addresses, this is how it works:
Router#tclsh
Router(tcl)#foreach address {
+>1.1.1.1
+>2.2.2.2
+>3.3.3.3
+>150.1.4.4
+>} { ping $address repeat 3 size 1500 }
Type escape sequence to abort.
Sending 3, 1500-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
!!!
Success rate is 100 percent (3/3), round-trip min/avg/max = 4/8/12 ms
Type escape sequence to abort.
Sending 3, 1500-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
!!!
Success rate is 100 percent (3/3), round-trip min/avg/max = 4/4/4 ms
Type escape sequence to abort.
Sending 3, 1500-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds:
!!!
Success rate is 100 percent (3/3), round-trip min/avg/max = 1/1/1 ms
Type escape sequence to abort.
Sending 3, 1500-byte ICMP Echos to 150.1.4.4, timeout is 2 seconds:
!!!
Success rate is 100 percent (3/3), round-trip min/avg/max = 1/4/8 ms
Router(tcl)#tclquit
The script above will ping all my IP addresses 3 times and set the packet size to 1500 bytes. Something you should remember is that you need to type tclquit to exit TCLSH scripting.
You can use TCLSH on routers and most switches. In case your switch doesn’t support TCLSH you can also create a macro that does a similar job. Here’s how to do it:

very useful… Thanks Rene !!
Hello Team,
I have access to a virtual Cisco lab and I tried the ping script, but when I enter TCL mode there is no foreach option. Does it depend on IOS version?
https://cdn-forum.networklessons.com/uploads/default/original/2X/f/f376f28a44f0fab734dea282ed74ef2da5c4d0db.png
Thank you.
Regards,
Hello Milan
When using the TCLSH configuration mode, the scripting commands do not appear in the context sensitive help using the “?”. Only the CLI commands will appear there, not the scripting commands. As you can see from my test below, the
foreach
command does not appear as a command, but is accepted as part of the script:I hope this has been helpful!
Laz
Thank you Laz for your time to replay, all is clear now