由于工作的需要,經(jīng)常要手工登錄到5620E進(jìn)行數(shù)據(jù)的配制,總覺(jué)得來(lái)來(lái)回都是那幾條命令,就想想能不能寫(xiě)些腳本讓其自動(dòng)運(yùn)行,這樣省時(shí)又省力。想到不如做到,立即上網(wǎng)查查相關(guān)資料,最后決定利用SecureCRT可執(zhí)行VBS腳本的這個(gè)特點(diǎn)來(lái)實(shí)現(xiàn)我想要的功能。
程序的大概思路是,寫(xiě)一個(gè)AddOnu.vbs的腳本文件,使其能從OnuIp.txt配制文件中循環(huán)的讀取Onu的IP地址及相關(guān)配制信息,程序根據(jù)這些信息可實(shí)現(xiàn)批量的對(duì)Oun進(jìn)行自動(dòng)登錄、寫(xiě)數(shù)據(jù)、保存、退出等一條龍服務(wù)。在OnuIp.txt中設(shè)置好你所要配制的Onu信息后,你只要在SecureCRT-腳本-運(yùn)行 中選擇執(zhí)行該腳本,即可端上一杯茶慢慢品味,5620E的數(shù)據(jù)配制不再讓你擔(dān)憂,程序一步到位幫你搞定。但一個(gè)重要的前提是這些Onu都是在線可連接的而且登錄密碼也都是一樣的,如其中有一臺(tái)不能正常連接或無(wú)法登錄,程序?qū)o(wú)法繼續(xù)運(yùn)行下去。
以下是各個(gè)文件的具休內(nèi)容:
--------------------AddOnu.vbs--------------------
# $language = "VBScript"
# $interface = "1.0"
Const ForReading = 1
Sub Main
On error resume Next
Dim OnuIp,MgIp,StartVlan,EndVlan,OnuNum,IPFileName,ErronNO
'斷開(kāi)主機(jī)連接
crt.session.Disconnect
'MsgBox(IPFileName)
'Set objFolder = objFSO.GetFolder(Server.MapPath("/"))
IPFileName="ONUIP.txt"
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
if not (fso.fileexists(IPFileName)) Then
nResult = MsgBox("在當(dāng)前目錄中找不到名稱(chēng)為""" & _
IPFileName & _
""" 的配制文件," & vbcrlf & vbcrlf & _
vbtab & "手工指定文件目錄請(qǐng)按<是>" & vbcrlf & vbcrlf & _
vbtab & "退出請(qǐng)按<否>" & vbcrlf & vbcrlf , vbYesNo)
If nResult=vbYes Then
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "Text Files|*.txt"
objDialog.FilterIndex = 2
objDialog.InitialDir = g_shell.SpecialFolders("MyDocuments")
nResult = objDialog.ShowOpen
If nResult <> 0 Then
IPFileName = objDialog.FileName
End If
Else
MsgBox("exit")
Exit Sub
End If
End If
Set f = fso.OpenTextFile(IPFileName, ForReading, 0)
Dim LineStr,params
Do While f.AtEndOfStream <> True
' Read each line of the printers file. '
'f.skipline跳過(guò)一行
' ErronNom=0
LineStr = f.Readline
If Trim(LineStr)<>"" andLeft(LineStr,2)<>"//" and Instr(LineStr, "|") > 0Then
'MsgBox LineStr
params = Split( LineStr,"|" )
OnuIp= params(0)
MgIp= params(1)
MgWgIp = params(2)
StartVlan = params(3)
EndVlan= params(4)
If StartVlan>EndVlan Then
MsgBox("起始Vlan不能大于結(jié)束Vlan,程序已退出!")
Exit Sub
End If
OnuNum = params(5)
'MsgBox(params(0)¶ms(1)¶ms(2)¶ms(3)¶ms(4)¶ms(5))
crt.Screen.Synchronous = True
crt.session.Connect("/telnet "& OnuIp )
'If crt.session.Connect("/telnet "& OnuIp )= False Then
'crt.Screen.WaitForString ("User name:", 1)
'MsgBox "Failed to connect to " & OnuIp
'ErronNom = 1
'End If
crt.screen.WaitForString "User name:",10
crt.screen.send "root" &vbCR
crt.screen.WaitForString "User password:",10
crt.screen.send "****" &vbCR
crt.screen.WaitForString "[n]:",2
crt.screen.send "y" &vbCR
crt.screen.WaitForString ">",10
crt.screen.send "enable" &vbCR
crt.screen.WaitForString "#",2
crt.screen.send "config" &vbCR
crt.screen.WaitForString "#",2
crt.screen.send "switch language-mode" &vbCR
Dim Str2
Str2=Split(MgIp,".")
crt.screen.WaitForString "#",2
crt.Screen.Send "tid-template add 33 format %05u parameter-list g+58900 name zte " &vbCR
crt.Screen.Send "tid-template add 34 format %05u parameter-list r name TD "&vbCR&vbCR
crt.Screen.Send "vlan 3000" &vbCR &vbCR
crt.Screen.Send "port vlan 3000 0/0 1" &vbCR
crt.Screen.Send "vlan "& StartVlan &" to "& EndVlan &"" &vbCR
crt.Screen.Send "y" &vbCR
crt.Screen.Send "port vlan"& StartVlan &" to "& EndVlan & "0/0 1" &vbCR
crt.Screen.Send "y" &vbCR
crt.Screen.Send "undo service-port all" &vbCR
crt.Screen.Send "y" &vbCR
crt.Sleep 1000
Dim i,j
j=0
For i= StartVlan to EndVlan
crt.Screen.Send " service-port "& j &"vlan "& i &" eth 0/1/"& j+1 &"user-vlan untaggedrx-cttr 1 tx-cttr 1" &vbCR
crt.Sleep 1000
j=j+1
Next
crt.Screen.Send Chr(13)
crt.Screen.Send "interface vlanif 3000 " &vbCR
crt.Screen.Send " ip address "& MgIp &" "& MgWgIp &vbCR
crt.Screen.Send " quit" &vbCR
crt.Screen.Send " voip" &vbCR
crt.Screen.Send " ip address media "& MgIp &""& Str2(0)&"."& Str2(1)&"."&Str2(2)&"."&"1 " &vbCR
crt.Screen.Send " ip address signaling "& MgIp &" " &vbCR
crt.Screen.Send " quit" &vbCR
crt.Screen.Send "interface h248 "& OnuNum &"" &vbCR
crt.Screen.Send "y" &vbCR
crt.Screen.Send "if-h248 attribute mgip "& MgIp &"mgport 2944 transfer udp" &vbCR &vbCR
crt.Screen.Send "if-h248 attribute mgcip_1 10.53.4.22mgcport_1 2944" &vbCR &vbCR
crt.Screen.Send "if-h248 attribute mg-media-ip "& MgIp &"" &vbCR &vbCR
crt.Screen.Send "if-h248 attribute profile-index 1 start-negotiate-version 2" &vbCR &vbCR
crt.Screen.Send "tid-format rtp prefix RTP/ template 34 pstn prefix AG template 33" &vbCR
crt.Screen.Send "mg-ringmode add 0 10 26 " &vbCR
crt.Screen.Send "if-h248 attribute profile-index 5" &vbCR &vbCR
crt.Screen.Send " quit" &vbCR
crt.Screen.Send " esl user " &vbCR
Dim m
For m=1 to 16
crt.Screen.Send "mgpstnuser add 0/2/"& m &"0 terminalid "&m &"telno 0000000" &vbCR &vbCR
crt.Sleep 1000
Next
crt.Screen.Send Chr(13)
crt.Screen.Send " quit" &vbCR
crt.Screen.Send "ip route-static 10.53.4.0 255.255.255.0 10.51."& Str2(2) &".1" &vbCR
crt.Screen.Send "ip route-static 10.51.0.0 255.255.0.0 10.51."& Str2(2) &".1 " &vbCR
crt.Screen.Send "snmp-agent trap source vlanif 100" &vbCR
crt.Screen.Send "save" &vbCR &vbCR
crt.screen.WaitForString "保存完成",2000
crt.screen.WaitForString "(config)#",5
crt.screen.send "quit" &vbCR
crt.screen.WaitForString "#",10
crt.screen.send "quit" &vbCR
crt.screen.send "y" &vbCR
crt.screen.WaitForString "請(qǐng)重建連接后登錄",1000
crt.Sleep 2000
crt.Screen.Synchronous = False
End If
Loop
End Sub
--------------------OnuIp.txt--------------------
// ONU管理IP |ONU語(yǔ)音IP |語(yǔ)音IP網(wǎng)關(guān)地址 | 起始VLan | 結(jié)束VLan | ONU編號(hào)
192.168.1.23|192.168.2.33|255.255.255.0|349|364|3
192.168.1.24|192.168.2.33|255.255.255.0|365|380|4
腳本代碼:
巧用SecureCRT vbs腳本批量對(duì)華為5620E進(jìn)行數(shù)據(jù)配制.rar (2.58 KB)
遺留問(wèn)題:
此腳本無(wú)法判斷oun是否接成功,如有哪位朋友能實(shí)現(xiàn)這個(gè)功能或?qū)υ撃_本進(jìn)行友好的完善,歡迎共同討論分享,QQ:16845612!