TCLSH and Macro Ping Test on Cisco IOS

When you are studying for CCIE  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 ping all these IP addresses automatically, 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:

We're Sorry, Full Content Access is for Members Only...

If you like to keep on reading, Become a Member Now! Here is why:

  • Learn any CCNA, CCNP and CCIE R&S Topic. Explained As Simple As Possible.
  • Try for Just $1. The Best Dollar You’ve Ever Spent on Your Cisco Career!
  • Full Access to our 786 Lessons. More Lessons Added Every Week!
  • Content created by Rene Molenaar (CCIE #41726)

1589 Sign Ups in the last 30 days

satisfaction-guaranteed
100% Satisfaction Guaranteed!
You may cancel your monthly membership at any time.
No Questions Asked!

Forum Replies

  1. very useful… Thanks Rene !!

  2. 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:

    R1#tclsh
    R1(tcl)#f?
    format  fsck  
    
    R1(tcl)#foreach address {
    +>(tcl)#
    

    I hope this has been helpful!

    Laz

  3. Thank you Laz for your time to replay, all is clear now :slight_smile:

  4. Hello Seng

    Thanks for pointing this out. I’m not sure if the issue is with the script, the syntax or the support. Cisco IOS version 15.2(4)M1 does support TCL scripts according to the Cisco Feature Navigator. Can you tell us a little bit more about what error messages you are getting? Also, can you tell us the platform you are running this on? All of these will affect whether this script will actually run on your setup. Let us know so we can help you further.

    I hope this has been helpful!

    Laz

1 more reply! Ask a question or join the discussion by visiting our Community Forum