Cisco News

Loading...

Friday, February 15, 2008

Ping A Group of IP Addresses with a Script on Cisco Routers and Switches

Here is a quick rundown of the scripts to ping multiple IPs on a Cisco Router or Switch.

IOS Router Using Tcl

Use the show ip aliases command to collect the IP addresses from all of the devices you would like to ping, and paste the results into notepad. Do a find and replace for Interface, and all of the blank space up to the IP address. Replace with nothing, leaving only the IP addresses.

Router#show ip aliases
Address Type IP Address Port
Interface 10.2.2.2
Interface 10.3.3.3
Interface 10.1.1.1
Interface 10.4.4.4

Then paste the IP addresses into the following script

tclsh



foreach ip {

10.2.2.2
10.3.3.3
10.1.1.1
10.4.4.4
} {ping $ip}

Router#tclsh
Router(tcl)#foreach ip {
10.1.1.1
10.2.2.2
10.3.3.3
10.4.4.4
} {ping $ip}

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.2.2.2, 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 10.3.3.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 10.1.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 10.4.4.4, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/4 ms

type tclquit to exit from Tcl Shell

IOS Switch Using a Macro


Use the show ip aliases command to collect the IP addresses from all of the devices you would like to ping, and paste the results into notepad. Do a find and replace for Interface, and all of the blank space up to the IP address. replace with "do ping "


Switch#show ip aliases
Address Type IP Address Port
Interface 10.2.2.2
Interface 10.3.3.3
Interface 10.1.1.1
Interface 10.4.4.4

Then paste the IP addresses into the following script

enable
conf t

macro name ping
do ping 10.2.2.2
do ping 10.3.3.3
do ping 10.1.1.1
do ping 10.4.4.4
@

Macro global apply ping

Switch#enable
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#
Switch(config)#macro name ping
Enter macro commands one per line. End with the character '@'.
do ping 10.2.2.2
do ping 10.3.3.3
do ping 10.1.1.1
do ping 10.4.4.4
@
Switch(config)#
Switch(config)#Macro global apply ping

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.2.2.2, 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 10.3.3.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 10.1.1.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 10.4.4.4, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/4 ms

0 comments: