If you wish to execute a ping sweep from your router you can use the following TCL ping script:
foreach ip {
172.16.1.1
172.16.1.2
172.16.1.3
172.16.1.4
} { puts [ exec "ping $ip" ] }
Mind $ip is merely a variable, so any other could be used instead.
There are various ways on how you can actually run the script.
The basic way is to execute it from IOS command shell:
Router#tclsh
Router(tcl)#foreach ip {
+>(tcl)#172.16.1.1
+>(tcl)#172.16.1.2
+>(tcl)#172.16.1.3
+>(tcl)#172.16.1.4
+>(tcl)#} { puts [ exec "ping $ip" ] }
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/44/100 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.1.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 8/27/56 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.1.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/26/96 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.1.4, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/27/52 ms
There is another way as well. You could save the TCL script to flash memory of your router and address to the script by using Embedded Event Manager (EEM) functionality by a trigger:
// no trigger example
event manager applet Ping
event none
action 1.0 cli command "enable"
action 1.1 cli command "tclsh flash:tcl/ping.tcl"
// when an interface goes up trigger example
event manager applet Clear
event syslog pattern "LINK-3-UPDOWN.*to up"
action 1.0 cli command "enable"
action 1.1 cli command "tclsh flash:tcl/ping.tcl"
Let’s go further and make a KRON job for our TCL script to ping sweep every hour or 60 minutes:
evilttl(config)#kron policy-list Ping
evilttl(config-kron-policy)#cli tclsh flash:tcl/ping.tcl
evilttl(config)#kron occurrence Ping in 60 recurring
evilttl(config-kron-policy)#policy-list Ping
evilttl(config)#show kron schedule