Cisco IOS脚本和宏命令

脚本模版:

tclsh

foreach TEST {

116.228.7.174

192.168.1.1

} { ping 202.96.209.5 repeat 10 so $TEST }


Cisco IOS 提供强大的脚本和宏命令来帮助工程师来测试网络。提供一个高效,准确,简单的测试全网连通性的问题。


      Cisco IOS 上路由器和交换机使用的命令不一样。先从路由器开始:


      Router,使用的是脚本来测试。只用我们把这些脚本在一个记事本编辑好,然后贴到CLI 中就可以让设备自动完成了。路由器不能存放脚本。我们拿以下的例子来说,下面是脚本文件:


      tclsh

      foreach TEST {

      192.168.255.1

      192.168.255.2

      192.168.255.3

      192.168.255.4

      192.168.255.5

      192.168.255.6

      192.168.255.7

      192.168.255.8

      192.168.255.9

      192.168.255.10

      } { ping $TEST repeat 5 }


      上述中,TEST 是一个变量,你可以随便起。我们设定了ping 的次数为5 次。

      然后在路由器的全局模式下按照以下操作:


      Router>enable

      Router#tclsh

      Router(tcl)#


      然后把上述的脚步复制到CLI 中。路由器会自动执行。


      Rack17R1#tclsh

      +>foreach TEST {

      +>192.168.255.1

      +>192.168.255.2

      +>192.168.255.3

      +>192.168.255.4

      +>192.168.255.5

      +>192.168.255.6

      +>192.168.255.7

      +>192.168.255.8

      +>192.168.255.9

      +>192.168.255.10

      +>} { ping $TEST repeat 5 }


      Type escape sequence to abort.

      Sending 5, 100‐byte ICMP Echos to 192.168.255.1, timeout is 2 seconds:

      !!!!!

      Success rate is 100 percent (5/5), round‐trip min/avg/max = 1/2/4 ms

      Type escape sequence to abort.

      Sending 5, 100‐byte ICMP Echos to 192.168.255.2, timeout is 2 seconds:

      !!!!!

      Success rate is 100 percent (5/5), round‐trip min/avg/max = 56/58/60 ms

      Type escape sequence to abort.

      Sending 5, 100‐byte ICMP Echos to 192.168.255.3, timeout is 2 seconds:

      !!!!!

      Success rate is 100 percent (5/5), round‐trip min/avg/max = 84/86/89 ms

      Type escape sequence to abort.

      Sending 5, 100‐byte ICMP Echos to 192.168.255.4, timeout is 2 seconds:

      !!!!!

      Success rate is 100 percent (5/5), round‐trip min/avg/max = 140/147/164 ms

      Type escape sequence to abort.

      Sending 5, 100‐byte ICMP Echos to 192.168.255.5, timeout is 2 seconds:

      !!!!!

      Success rate is 100 percent (5/5), round‐trip min/avg/max = 140/142/144 ms

      Type escape sequence to abort.

      Sending 5, 100‐byte ICMP Echos to 192.168.255.6, timeout is 2 seconds:

      !!!!!

      Success rate is 100 percent (5/5), round‐trip min/avg/max = 56/59/65 ms

      Type escape sequence to abort.

      Sending 5, 100‐byte ICMP Echos to 192.168.255.7, timeout is 2 seconds:

      !!!!!

      Success rate is 100 percent (5/5), round‐trip min/avg/max = 1/2/4 ms

      Type escape sequence to abort.

      Sending 5, 100‐byte ICMP Echos to 192.168.255.8, timeout is 2 seconds:

      .....

      Success rate is 0 percent (0/5)

      Type escape sequence to abort.

      Sending 5, 100‐byte ICMP Echos to 192.168.255.9, timeout is 2 seconds:

      !!!!!

      Success rate is 100 percent (5/5), round‐trip min/avg/max = 1/2/4 ms

      Type escape sequence to abort.

      Sending 5, 100‐byte ICMP Echos to 192.168.255.10, timeout is 2 seconds:

      !!!!!

      Success rate is 100 percent (5/5), round‐trip min/avg/max = 56/57/60 ms

      Rack17R1(tcl)#


      我们看到了全网都可达,如果不通,一定要找到时什么原因。如果不知道原因,就需要查找原因。这样你就可以用一个命令来测试全网的可达性。


==========================================================================================

交换机就使用使用宏命令来测试。宏命令是可以保存在交换机上的。


      宏命令如下:(全局模式下使用)


      macro name TEST

      do ping 192.168.255.1

      do ping 192.168.255.2

      do ping 192.168.255.3

      do ping 192.168.255.4

      do ping 192.168.255.5

      do ping 192.168.255.6

      do ping 192.168.255.7

      do ping 192.168.255.8

      do ping 192.168.255.9

      do ping 192.168.255.10

      @

      把上面的宏命令复制到CLI 中后。我们就可以调用它了。

      Switch(config)#macro global apply TEST 就可以让交换机自己调用刚才创建的宏来测试。

      =============================

      Rack17SW1(config)#macro global apply TEST

      Type escape sequence to abort.

      Sending 5, 100‐byte ICMP Echos to 192.168.255.1, timeout is 2 seconds:

      !!!!!

      Success rate is 100 percent (5/5), round‐trip min/avg/max = 1/4/9 ms

      Type escape sequence to abort.

      Sending 5, 100‐byte ICMP Echos to 192.168.255.2, timeout is 2 seconds:

      !!!!!


      Success rate is 100 percent (5/5), round‐trip min/avg/max = 51/57/59 ms

      Type escape sequence to abort.

      Sending 5, 100‐byte ICMP Echos to 192.168.255.3, timeout is 2 seconds:

      !!!!!

      Success rate is 100 percent (5/5), round‐trip min/avg/max = 25/30/34 ms

      Type escape sequence to abort.

      Sending 5, 100‐byte ICMP Echos to 192.168.255.4, timeout is 2 seconds:

      !!!!!

      Success rate is 100 percent (5/5), round‐trip min/avg/max = 84/89/101 ms

      Type escape sequence to abort.

      Sending 5, 100‐byte ICMP Echos to 192.168.255.5, timeout is 2 seconds:

      !!!!!

      Success rate is 100 percent (5/5), round‐trip min/avg/max = 83/87/93 ms

      Type escape sequence to abort.

      Sending 5, 100‐byte ICMP Echos to 192.168.255.6, timeout is 2 seconds:

      !!!!!

      Success rate is 100 percent (5/5), round‐trip min/avg/max = 50/57/59 ms

      Type escape sequence to abort.

      Sending 5, 100‐byte ICMP Echos to 192.168.255.7, 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.255.8, 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.255.9, 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.255.10, timeout is 2 seconds:

      !!!!!      

      Success rate is 100 percent (5/5), round‐trip min/avg/max = 50/57/59 ms

      Rack17SW1(config)#

      

      这样在交换机上就可以测试全网可达性了。

      那么我们怎么去复制网络中的地址呢?我有两种方式:

      

      1. sh ip int bri

      Rack17R1#sh ip int bri

      Interface IP‐Address OK? Method Status Protocol

      FastEthernet0/0 192.168.255.1 YES NVRAM up up

      FastEthernet0/1 192.168.255.2 YES NVRAM up up

      我们看到这种方式比较笨重。

      

      2. sh ip alias

      Rack17R1#sh ip alias

      Address Type IP Address Port

      Interface 192.168.255.1

      Interface 192.168.255.2

      Interface 192.168.255.3

      我们看到第二种方式比较简单。我们可以直接使用记事本的替换功能将前面的单词替换掉。就可以直接使用了。













本文转自Grodd51CTO博客,原文链接:http://blog.51cto.com/juispan/1950746,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值