天天看點

VBS一鍵配置VOIP腳本(其中包括VBS操作JS網頁中的按鈕事件--直接執行确認按鈕中的腳本代碼)

Dim ws,fso,IE

Set IE = WScript.createobject("InternetExplorer.Application")

Set ws = WScript.CreateObject ("WSCript.shell")

Set fso=CreateObject("scripting.filesystemobject")

Const reboot="/content.cgi?form=M_SAV"

IE.menubar=0 '顯示IE對象菜單欄

IE.AddressBar=1 '顯示IE對象位址欄

IE.ToolBar=0 '顯示IE對象工具欄

IE.StatusBar=1 '不顯示IE對象狀态欄

IE.FullScreen=0 '全屏化IE對象

IE.Height=768

IE.Width=1024

IE.Resizable=1 '設定IE對象大小是否可以被改動

IE.visible=1 '設定是否可見 

'IE.Navigate "192.168.46.3"

'==============讀Config配置檔案=========

    

filepath=createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path

file_config=filepath&"\config.ini"

Set file=fso.OpenTextFile(file_config,1)

'===========取第一行資料:号碼==============

OneLine=file.ReadLine

OneLineStr=Split(OneLine,"=")

OneLineCount=UBound(split(OneLine,"="))

'MsgBox OneLineStr(1)                   

'===============取第二行資料:密碼===========

TwoLine=file.ReadLine

TwoLineStr=Split(TwoLine,"=")

TwoLineCount=UBound(split(TwoLine,"="))

'MsgBox TwoLineStr(1)

'===============取第三行資料:VOIP服務位址============

ThreeLine=file.ReadLine

ThreeLineStr=Split(ThreeLine,"=")

ThreeLineCount=UBound(split(ThreeLine,"="))

'MsgBox ThreeLineStr(1)

'===============取第四行資料:對講裝置位址============

FourLine=file.ReadLine

FourLineStr=Split(FourLine,"=")

FourLineCount=UBound(split(FourLine,"="))

'MsgBox FourLineStr(1)

'===============取第五行資料:浏覽器安裝目錄============

FiveLine=file.ReadLine

FiveLineStr=Split(FiveLine,"=")

FiveLineCount=UBound(split(FiveLine,"="))

'MsgBox FiveLineStr(1)

'MainWeb()

Main()

'==================================================

Function Main()

    IE.Navigate FourLineStr(1)

        

    Do 

        WScript.Sleep 500

    Loop Until IE.ReadyState=4

    Login()

    SipSetting()

    InputParm()

    VOIP()

    RebootSys()

End Function 

'======================================================

'登入系統

Function Login()

    WScript.Sleep 1000

    ws.SendKeys "^a"

    WScript.Sleep 200

    ws.SendKeys "admin"

    ws.SendKeys "{TAB}"

    ws.SendKeys "{ENTER}"

'================================================

'進入sipsetting菜單

Function SipSetting()

    If IE.ReadyState=4 Then 

        WScript.Sleep 1000

        ws.SendKeys "{TAB 5}"

        ws.SendKeys "{ENTER}"

        ws.SendKeys "{TAB}"

        WScript.Sleep 2000

    Else 

     MsgBox "進入配置界面失敗!"

     

    End If 

'=============================================

'切換輸入界面

Function InputParm()

    WScript.Sleep 200    

    ws.SendKeys "{DOWN}"  '選擇開啟狀态

    WScript.Sleep 300

'=========================================

'配置參數

Function VOIP()

    ws.SendKeys OneLineStr(1)  'display name

    ws.SendKeys OneLineStr(1)   'user number

    ws.SendKeys OneLineStr(1)   'auth id

    ws.SendKeys "{TAB}"    

    WScript.Sleep 200            

    ws.SendKeys TwoLineStr(1)   'password

    ws.SendKeys ThreeLineStr(1)   'proxy ip

    ws.SendKeys "{TAB}"        'domain

    ws.SendKeys ThreeLineStr(1)

    '=============儲存===========

    ws.SendKeys "{TAB 48}"

    WScript.Sleep 500

    WScript.Sleep 1500

'========================================================

'修改參數後重新開機

Function RebootSys()

    ws.SendKeys "{F4}"

    ws.SendKeys FourLineStr(1)&reboot 

    WScript.Sleep 500    

'   Set test=IE.document.getElementsByTagName ("Button")

    WScript.Sleep 2000

    Set ALL = Ie.Document.getElementsByTagName("input")  '檢測網頁元素是否标簽為input,且值等于Reboot

    For Each i In ALL

    If i.value="Reboot" Then

       'i.Click  '點選reboot按鈕

       

        Ie.Document.parentwindow.execScript("top.location='content.cgi?_method_=reboot'")  '直接執行reboot确認操作

        Exit For

    End If

    Next

    WScript.Sleep 3000    

    MsgBox "配置已完成,裝置正在重新開機,請耐心等待...",,"提示"

    If ws.AppActivate("來自網頁的消息") Then 

        MsgBox "配置已完成,裝置正在重新開機,請耐心等待...",,"提示"

        'MsgBox "配置未成功,請重新檢查配置!",,"提示"

'====================================================================

Function MainWeb()

    '=============啟動位址=====================

'方式一:自定義浏覽器啟動,需配置路徑

'   Function login()

'       ws.run FiveLineStr(1)

'       WScript.Sleep 3000

'       ws.SendKeys "{F4}"

'       WScript.Sleep 200

'       ws.SendKeys "^a"

'       WScript.Sleep 500

'       ws.SendKeys FourLineStr(1)

'       ws.SendKeys "{ENTER}"

                

'   End Function    

'方式二:用系統預設浏覽器啟動 

    ws.Run FourLineStr(1)

    '===============登入裝置=====================

    WScript.Sleep 5000

    '============進入sip setting菜單=============

    ws.SendKeys "{TAB 5}"

    '==============進入編輯狀态=======================

    '==============配置VOIP================

    '===============重新開機==========

    ws.SendKeys "{TAB 18}"

    ws.SendKeys "{TAB 2}"

        MsgBox "配置未成功,請重新檢查配置!",,"提示"

Set ws=Nothing 

Set IE=Nothing 

Set fso=Nothing 

##################################################網頁部分JS代碼:

<div id="content" width="650">

<form name="M_SAV" method="GET" enctype="multipart/form-data" onReset="" action="content.cgi">

<input type=HIDDEN name="_method_" value="apply">

<input type=HIDDEN name="form" value="M_SAV">

<input type=HIDDEN name="commit" value="0">

<table id="cFORM" width="650" border="0" cellspacing="0" cellpadding="0" >

<tr><td>&nbsp</td></tr>

</table><table width="500"><td align="center">

<input type=BUTTON onclick="javascript:if ( confirm('Reboot') ) top.location='content.cgi?_method_=reboot';" target="_top" value="Reboot"></a>

</td></table></form>

技術改變世界!

--狂詩絕劍

繼續閱讀