on error resume next
dim n,sleep_time,ip,slot,link,ip1,ip2
num=inputbox("请输入OLT重启ONU的次数")
If IsEmpty(num) Then
wscript.quit
end if
num=num*1
do while (num<1 or num>500)
num=num*1
if num < 1 then
num=inputbox("重启次数不能小于0,请重新输入OLT重启ONU的次数")
If IsEmpty(num) Then
wscript.quit
end if
end if
if num > 500 then
num=inputbox("重启次数不能大于500,请重新输入OLT重启ONU的次数")
If IsEmpty(num) Then
wscript.quit
end if
end if
num=num*1
loop
sleep_time=inputbox("请输入重启间隔时间,以秒为单位")
if sleep_time="" then
sh.popup "选择了取消,测试终止",3,"取消测试...",64
wscript.quit
end if
do while (sleep_time<1 or sleep_time>500)
sleep_time=sleep_time*1
if sleep_time < 1 then
sleep_time=inputbox("重启间隔时间不能小于0,请重新输入重启间隔时间,以秒为单位")
If IsEmpty(sleep_time) Then
wscript.quit
end if
end if
if sleep_time > 500 then
sleep_time=inputbox("重启等待时间不能大于500,请重新输入重启间隔时间,以秒为单位")
If IsEmpty(sleep_time) Then
wscript.quit
end if
end if
sleep_time=sleep_time*1
loop
sleep_time=sleep_time*1
ip=inputbox("请输入OLT的ip地址")
if ip="" then
sh.popup "选择了取消,测试终止",3,"取消测试...",64
wscript.quit
end if
'加入OLT的ip地址
ip1 = "5.5.5.10"
ip2 = "5.5.5.20"
'目前OLT只有2台,ip分别为5.10跟5.20,如果以后增加了更多的olt或者OLT的ip地址改变.
'则需要对这里进行修改,并在下面的判断中增加ip3,ip4等等,
''''''将此段复制''''
do
if ip=ip1 then
exit do
end if
''''''将此段复制,并把ip1改成ip2等等''''
'将ip2改成最后一台olt的ip地址
if ip=ip2 then
exit do
else
ip=inputbox("OLT的IP地址输入错误,请重新输入OLT的ip地址")'
if ip="" then
sh.popup "选择了取消,测试终止",3,"取消测试...",64
wscript.quit
end if
end if
loop
slot=inputbox("请输入Slot号")
if slot="" then
sh.popup "选择了取消,测试终止",3,"取消测试...",64
wscript.quit
end if
do while (slot<1 or slot>30)
slot=slot*1
if slot < 1 then
slot=inputbox("Slot号不能小于0,请重新输入Slot号")
If IsEmpty(slot) Then
wscript.quit
end if
end if
if slot > 30 then
slot=inputbox("Slot号不能大于30,请重新输入Slot号")
If IsEmpty(slot) Then
wscript.quit
end if
end if
slot=slot*1
loop
link=inputbox("请输入link号")
if link="" then
sh.popup "选择了取消,测试终止",3,"取消测试...",64
wscript.quit
end if
do while (link<1 or link>8)
link=link*1
if link < 1 then
link=inputbox("link号不能小于0,请重新输入link号")
If IsEmpty(link) Then
wscript.quit
end if
end if
if link > 8 then
link=inputbox("link号不能大于8,请重新输入link号")
If IsEmpty(link) Then
wscript.quit
end if
end if
link=link*1
loop
'建立Shell对象
set sh=WScript.CreateObject("WScript.Shell")
'提示测试开始.
m=sh.popup ("参数设置完成,马上开始测试,在测试过程中,如果需要终止测试,请点击取消",3,"开始测试...",4)
if m=7 then
sh.popup "选择了取消,测试终止",3,"取消测试...",64
wscript.quit
end if
m=sh.popup ("OLT第1次重启ONU,共需重启" & num & "次本窗口会自动关闭,并开始测试",3,"开始测试...",4)
if m=7 then
sh.popup "选择了取消,测试终止",3,"取消测试...",64
wscript.quit
end if
'循环测试
dim i
i=0
while i<num
'执行重启过程
sh.Run "telnet.exe"
WScript.Sleep 200
'向telnet发送我们平时录入的命令
sh.SendKeys "open " & ip
WScript.Sleep 200
sh.AppActivate "{ENTER}"
WScript.Sleep 200
sh.SendKeys "{ENTER}"
WScript.Sleep 200
'发送登陆用户User
sh.AppActivate "telnet " & ip
sh.SendKeys " {ENTER}"
WScript.Sleep 200
'发送登陆密码pass
sh.AppActivate "telnet " & ip
sh.SendKeys " {ENTER}"
WScript.Sleep 200
'发送登陆用户User
sh.AppActivate "telnet " & ip
sh.SendKeys "en{ENTER}"
WScript.Sleep 200
'发送登陆密码pass
sh.AppActivate "telnet " & ip
sh.SendKeys " {ENTER}"
WScript.Sleep 200
'运行相关命令pwd
sh.AppActivate "telnet " & ip
sh.SendKeys "cd gpono{ENTER}"
WScript.Sleep 200
'运行相关命令pwd
sh.SendKeys "reset slot " & slot & " link " & link & " onulist all{ENTER}"
'运行退出TELNET登陆命令
WScript.Sleep 2000
sh.Run "taskkill /f /im telnet.exe"
'WScript.Sleep sleep_time
i=i+1
if i<num then
for x=1 to sleep_time
m=sh.popup ("Testcenter打流已进行" & x & "秒,OLT将在" & sleep_time-x & "秒后开始第" & i+1 & "次重启ONU,共需重启" & num & "次。本窗口会在等待时间结束时自动关闭。",1,"等待中....",4)
if m=7 then
sh.popup "选择了取消,测试终止",3,"取消测试...",64
wscript.quit
end if
next
end if
wend
msgbox ("测试结束,ONU被重启" & num & "次"),64,"测试完成"