О том, что такое TCL, можно почитать здесь. Не секрет, что CLI Cisco имеет возможность работы с подобного рода скриптами. Использовать их можно для разных целей. При подготовке к экзамену CCNP ROUTE руководство по лабораторным работам рекомендует пользоваться tcl-скриптами для тестирования сети, выполняя с его помощью множество команд ping без необходимости постоянного набора этих команд в CLI.
Для того, чтобы войти в режим написания скрипта, необходимо набрать команду tclsh в EXEC-моде.
R1#tclsh
После этого мы попадаем в режим работы с TCL.
R1(tcl)#
Напишем простой скрипт, позволяющий осуществить выполнение команды ping множества IP-адресов в нашей сети. Список сетевых адресов ниже:
172.16.1.1
172.16.2.1
172.16.3.1
172.16.3.33
172.16.3.65
172.16.3.97
172.16.4.1
172.16.4.33
172.16.4.65
172.16.4.97
172.16.12.1
172.16.12.2
172.16.23.2
172.16.23.3
172.16.34.3
172.16.34.4
172.16.2.1
172.16.3.1
172.16.3.33
172.16.3.65
172.16.3.97
172.16.4.1
172.16.4.33
172.16.4.65
172.16.4.97
172.16.12.1
172.16.12.2
172.16.23.2
172.16.23.3
172.16.34.3
172.16.34.4
Теперь напишем сам скрипт. Структура его такова:
foreach identifier {
value 1
value 2
.
.
.
value N
} { instruction 1
instruction 2
.
.
.
instruction M $identifier
}
С помощью оператора foreach создается цикл, который позволяет для каждого из N значений value выполнить M инструкций. Идентификатор $identifier по очереди будет перебирать все значения value, и завершится на M-том значении.
Применим это к нашей задаче: ping множества адресов. Скрипт будет выглядеть следующим образом:
R1(tcl)#foreach addresses {
+>(tcl)#172.16.1.1
+>(tcl)#172.16.2.1
+>(tcl)#172.16.3.1
+>(tcl)#172.16.3.33
+>(tcl)#172.16.3.65
+>(tcl)#172.16.3.97
+>(tcl)#172.16.4.1
+>(tcl)#172.16.4.33
+>(tcl)#172.16.4.65
+>(tcl)#172.16.4.97
+>(tcl)#172.16.12.1
+>(tcl)#172.16.12.2
+>(tcl)#172.16.23.2
+>(tcl)#172.16.23.3
+>(tcl)#172.16.34.3
+>(tcl)#172.16.34.4
+>(tcl)#} { ping $addresses}
+>(tcl)#172.16.1.1
+>(tcl)#172.16.2.1
+>(tcl)#172.16.3.1
+>(tcl)#172.16.3.33
+>(tcl)#172.16.3.65
+>(tcl)#172.16.3.97
+>(tcl)#172.16.4.1
+>(tcl)#172.16.4.33
+>(tcl)#172.16.4.65
+>(tcl)#172.16.4.97
+>(tcl)#172.16.12.1
+>(tcl)#172.16.12.2
+>(tcl)#172.16.23.2
+>(tcl)#172.16.23.3
+>(tcl)#172.16.34.3
+>(tcl)#172.16.34.4
+>(tcl)#} { ping $addresses}
После нажатия Enter скрипт начинает выполнятся. Мы видим, как все адреса, указанные в нашем скрипте, успешно протестировались:
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 = 1/2/4 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.2.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/10/24 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.3.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/14/36 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.3.33, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/6/16 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.3.65, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/10/24 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.3.97, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/10/20 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.4.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/13/36 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.4.33, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/14/36 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.4.65, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/9/28 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.4.97, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/9/24 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.12.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/9/36 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.12.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/9/16 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.23.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/7/20 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.23.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/12/36 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.34.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/5/12 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.34.4, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/16/36 ms
R1(tcl)#
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 = 1/2/4 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.2.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/10/24 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.3.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/14/36 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.3.33, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/6/16 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.3.65, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/10/24 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.3.97, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/10/20 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.4.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/13/36 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.4.33, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/14/36 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.4.65, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/9/28 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.4.97, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/9/24 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.12.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/9/36 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.12.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/9/16 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.23.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/7/20 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.23.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/12/36 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.34.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/5/12 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.34.4, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/16/36 ms
R1(tcl)#
Мы можем скопировать этот скрипт в тектовый редактор и выполнять его на всех устройствах, которые необходимо протестировать, экономя тем самым время.
Комментариев нет:
Отправить комментарий