start D:\SecureCRT\SecureCRT\SecureCRT.exe /SCRIPT D:\IOS\DyRouter.vbs /T /TELNET 127.0.0.1 %p 注:我是将CRT软件安装在D盘的根目录下,即 /SCRIPT之前的为CRT应用程序的安装目录。
而D:\IOS\DyRouter.vbs D:\IOS\DyRouter.vbs 则是一个方便日常使用的脚本,可以为任意目录。
在Win7和Vista系统下,命令行的设置应为:
在XP系统下可设置为:
另外:DyRouter.vbs脚本的代码是:
#$language = "VBScript"
#$interface = "1.0"
Option Explicit
Function mysubstring(srcString,bChar,eChar)
Dim fIndex,sIndex
fIndex=InStr(srcString,bChar)
sIndex=InStrRev(srcString,eChar)
mysubstring=Mid(srcString,fIndex+1,sIndex-fIndex-1)
End Function
'用来得到一个时间字符串,该字符串用来设置路由器的时间和日期
Function ciscoDate()
dim em, y,m,d,h
Dim nowDate
nowDate=Now()
em=Array("January","February","March","April","May","June","July","August","September","October","November","December")
y=Year(nowDate)
m=em(Month(nowDate)-1)
d=Day(nowDate)
h=Time()
ciscoDate=h & " " & m & " " & d & " " & y
End Function
Sub main
On Error Resume Next
crt.Screen.Synchronous = True
crt.Screen.WaitForString "Console port"
crt.Screen.Send VbCr
'得到第一行显示文本,主要从中提取设备名称
Dim firstLine
'用来存储标签的标题,也就是设备的名称
Dim tabTitle
firstLine=crt.Screen.Get2(1,1,1,100) '得到第一行文本
tabTitle=mysubstring(firstLine,"""","""") '调用方法取两个双引号之间的文本
crt.Window.Caption= tabTitle
'Dim result
'result = crt.screen.WaitForStrings("'yes' or 'no'", "[yes/no]:", "RETURN")
'If result = 1 Then
' crt.Screen.Send VbCr
'ElseIf result = 2 Then
' crt.Screen.Send "no" & VbCr
'ElseIf result = 3 Then
' crt.Screen.Send VbCr
'Else
' crt.Screen.Send VbCr
'End If
If crt.Screen.WaitForString("[yes/no]") Then
crt.Screen.Send "no" & VbCr
End If
crt.Screen.Send VbCr &VbCr
crt.Screen.WaitForString "Router>"
crt.Screen.Send "enable" & VbCr
crt.Screen.Send "conf terminal" & VbCr
crt.Screen.Send "no ip domain-lookup " & VbCr
crt.Screen.Send "hostname " & tabTitle & VbCr
crt.Screen.Send "line con 0" & VbCr
crt.Screen.Send "exec-timeout 0 0" & VbCr
crt.Screen.Send "logging synchronous" & VbCr
crt.Screen.Send "end" & VbCr
crt.Screen.Send "clock set " & ciscoDate() & VbCr
crt.Screen.Synchronous = False
End Sub
只需要新建一个记事本文件将代码拷入,后缀名该为.vbs就好了。
该脚本的作用是在每个开启的路由器上默认已经配置好了:
R1>enable
R1#config ter
R1(config-line)#logg synchronous
R1(config-line)#exec-t 0 0
R1(config)#no ip do lookup
***************
"C:\Program Files\VanDyke Software\SecureCRT\SecureCRT.exe" /SCRIPT d:\ios\DyRouter.vbs /T /TELNET 127.0.0.1 %p
*******************