Cisco IOS脚本和宏命令-阿里云开发者社区

开发者社区> 开发与运维> 正文
登录阅读全文

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,如需转载请自行联系原作者

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

其他文章
最新文章
相关文章