Wednesday, February 19, 2020

TCLSH and Macro Ping Test on Cisco Routers and Switches

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:
Switch#configure terminal
Switch(config)#macro name PING_TEST
Enter macro commands one per line. End with the character '@'.
do ping 192.168.12.1
do ping 192.168.13.1
do ping 192.168.1.1
@
First we will create a macro called PING_TEST. A macro can only be applied from the global configuration so we need to add “do” in front of our ping. The macro is stored in the running configuration as you can see here:
Switch#show run | begin macro
macro name PING_TEST
do ping 192.168.12.1
do ping 192.168.13.1
do ping 192.168.1.1
@
Now we will test our macro:
Switch(config)#macro global apply PING_TEST

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.12.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.13.1, 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.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/4 ms
Switch(config)#
From the global configuration just type macro global apply and the name of your macro. As you can see it pings all our IP addresses.
That’s all for now, I hope this helps you to save time at your CCIE lab exam!

No comments:

Post a Comment