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

9 comments:

Cosme said...

this is great! I have so many ips to ping and this saved my rear end! Awesome!
-Luis Cosme-
Comcast
Thanks!

Anonymous said...

Cosme is right! It saved us in our rear end.

This was useful in submitting bundles of Ip's

CCDA resources

Anonymous said...

My Ip's list are waiting. They are ready to be pinged.

south africa hunting safari

Anonymous said...

I want to use traffic geyser for this.

CCDA resources

Anonymous said...

I encourage others also to ping bundles of IP Addresses using Script on Cisco Routers and switches.

CCDA resources

Unknown said...

you can take this even further by creating an alias for the configuration command applying the macro

Switch(config)#alias configure ping-all macro global apply ping
Switch(config)#ping-all

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

However i have not yet figured out how to create an alias that will work in the same way from privileged executive mode. Any Ideas?

Jennifer Avina said...

Hi to everybody, here everyone is sharing such knowledge, so it’s fastidious to see this site, and I used to visit this blog daily.
security pole

Jennifer Avina said...

I don’t waste my free time that’s why I read the informative things when I got this blog I really enjoyed reading this.
custom camera systems for car wash

dreamer said...

nice
CISCO Routers