在进行大型网络的测试时(比如ccie的lab考试),如何快速的对各个节点进行测试,是非常重要的,IOS提供的tclsh脚本功能可帮助我们实现快速的的测试功能。
在支持tclsh的路由器上配(这里是r4):
ip rcmd rsh-enable
ip rcmd remote-host r4 150.1.4.4 r4 enable
ip rcmd source-interface Loopback0
在其它路由器上配:
ip rcmd rsh-enable
ip rcmd remote-host r4 150.1.4.4 r4 enable
在r4上配:
tclsh
foreach router {
150.1.1.1
150.1.2.2
150.1.3.3
150.1.4.4
150.1.5.5
150.1.6.6
} {
rsh $router shi \^ ip address \[0-9]
}
注意:shi是sh ip int brief的别名
将收集的地址列为如下格式:
ip address 150.1.1.1 255.255.255.255
ip address 150.1.11.1 255.255.255.0
ip address 183.1.17.1 255.255.255.0
ip address 183.1.123.1 255.255.255.0
ip address 150.1.2.2 255.255.255.255
ip address 183.1.2.2 255.255.255.0
ip address 183.1.123.2 255.255.255.0
ip address 150.1.3.3 255.255.255.255
ip address 204.12.1.3 255.255.255.0
ip address 183.1.123.3 255.255.255.0
ip address 183.1.0.3 255.255.255.0
ip address 150.1.4.4 255.255.255.255
ip address 183.1.46.4 255.255.255.0
ip address 183.1.0.4 255.255.255.0
ip address 150.1.5.5 255.255.255.255
ip address 183.1.58.5 255.255.255.0
ip address 183.1.0.5 255.255.255.0
ip address 150.1.6.6 255.255.255.255
ip address 183.1.46.6 255.255.255.0
ip address 54.1.1.6 255.255.255.0
将收集的地址列为如下格式:
150.1.1.1
150.1.11.1
183.1.17.1
183.1.123.1
150.1.2.2
183.1.2.2
183.1.123.2
150.1.3.3
204.12.1.3
183.1.123.3
183.1.0.3
150.1.4.4
183.1.46.4
183.1.0.4
150.1.5.5
183.1.58.5
183.1.0.5
150.1.6.6
183.1.46.6
54.1.1.6
在r4上继续执行:
tclsh
foreach router {
150.1.1.1
150.1.2.2
150.1.3.3
150.1.4.4
150.1.5.5
150.1.6.6
} {
puts "\n\n\n\n"
set hostname [rsh $router shi \^hostname]
puts "changing router to $hostname"
puts ""
puts "*************************************************************"
foreach address {
150.1.1.1
150.1.11.1
183.1.17.1
183.1.123.1
150.1.2.2
183.1.2.2
183.1.123.2
150.1.3.3
204.12.1.3
183.1.123.3
183.1.0.3
150.1.4.4
183.1.46.4
183.1.0.4
150.1.5.5
183.1.58.5
183.1.0.5
150.1.6.6
183.1.46.6
54.1.1.6
} {
puts "\n\n\n"
puts $hostname
puts $address
rsh $router ping $address
}
}