欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

VBS一键配置VOIP脚本代码

程序员文章站 2022-06-10 07:52:30
代码比较长,对vbs感兴趣的朋友可以参考一下 dim ws,fso,ie set ie = wscript.createob...

代码比较长,对vbs感兴趣的朋友可以参考一下

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 "^a"
    wscript.sleep 200
    ws.sendkeys "admin"
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{enter}"

end function 
'================================================
'进入sipsetting菜单
function sipsetting()

    if ie.readystate=4 then 
    
        wscript.sleep 1000
        ws.sendkeys "{tab 5}"
        wscript.sleep 500
        ws.sendkeys "{enter}"
        wscript.sleep 500
        ws.sendkeys "{tab}"
        wscript.sleep 500
        ws.sendkeys "{enter}"
        wscript.sleep 2000
    else 
    
     msgbox "进入配置界面失败!"
     
    end if 

end function 
'=============================================
'切换输入界面
function inputparm()

    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200    
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    
    
    ws.sendkeys "{down}"  '选择开启状态
    wscript.sleep 300

end function 
'=========================================
'配置参数
function voip()

    ws.sendkeys "{tab}"
    ws.sendkeys "^a"
    wscript.sleep 200
    ws.sendkeys onelinestr(1)  'display name
    
    ws.sendkeys "{tab}"
    ws.sendkeys "^a"
    wscript.sleep 200
    ws.sendkeys onelinestr(1)   'user number
    
    ws.sendkeys "{tab}"
    ws.sendkeys "^a"
    wscript.sleep 200
    ws.sendkeys onelinestr(1)   'auth id
    
    ws.sendkeys "{tab}"    
    wscript.sleep 200
    ws.sendkeys "^a"
    wscript.sleep 200            
    ws.sendkeys twolinestr(1)   'password
    
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "^a"
    wscript.sleep 200
    ws.sendkeys threelinestr(1)   'proxy ip
    
    ws.sendkeys "{tab}"        'domain
    wscript.sleep 200
    ws.sendkeys "^a"
    wscript.sleep 200
    ws.sendkeys threelinestr(1)
    
    '=============保存===========
    ws.sendkeys "{tab 48}"
    wscript.sleep 500
    ws.sendkeys "{tab}"
    wscript.sleep 500
    ws.sendkeys "{enter}"
    wscript.sleep 1500
    
end function 

'========================================================
'修改参数后重启
function rebootsys()

    wscript.sleep 500
    ws.sendkeys "{f4}"
    wscript.sleep 500
    ws.sendkeys "^a"
    wscript.sleep 200
    ws.sendkeys fourlinestr(1)&reboot 
    
    wscript.sleep 500    
    
'   set test=ie.document.getelementsbytagname ("button")
    ws.sendkeys "{enter}"
    
    wscript.sleep 2000
    
    set all = ie.document.getelementsbytagname("input")  '检测网页元素是否标签为input,且值等于reboot

    for each i in all

    if i.value="reboot" then

       'i.click  '点击reboot按钮
       
        wscript.sleep 1000
       
        ie.document.parentwindow.execscript("top.location='content.cgi?_method_=reboot'")  '直接执行reboot确认操作

        exit for

     
    end if

    next
    
    wscript.sleep 3000    
    
    msgbox "配置已完成,设备正在重启,请耐心等待...",,"提示"

    if ws.appactivate("来自网页的消息") then 
    
    
        ws.sendkeys "{enter}"
        wscript.sleep 2000
        
        msgbox "配置已完成,设备正在重启,请耐心等待...",,"提示"
        
    else 
        'msgbox "配置未成功,请重新检查配置!",,"提示"
        
    end if 

end function 


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

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)
'       wscript.sleep 500
'       ws.sendkeys "{enter}"
                
'   end function    

'方式二:用系统默认浏览器启动 
    ws.run fourlinestr(1)

    '===============登录设备=====================
    wscript.sleep 5000
    ws.sendkeys "^a"
    wscript.sleep 200
    ws.sendkeys "admin"
    ws.sendkeys "{tab}"
    ws.sendkeys "^a"
    wscript.sleep 200
    ws.sendkeys "admin"
    ws.sendkeys "{enter}"
    
    '============进入sip setting菜单=============
    wscript.sleep 2000
    ws.sendkeys "{tab 5}"
    wscript.sleep 500
    ws.sendkeys "{enter}"
    wscript.sleep 500
    ws.sendkeys "{tab}"
    wscript.sleep 500
    ws.sendkeys "{enter}"
    wscript.sleep 2000
    
    
    '==============进入编辑状态=======================
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200    
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "{tab}"
    wscript.sleep 200
    
    
    
    ws.sendkeys "{down}"  '选择开启状态
    wscript.sleep 300

    
    '==============配置voip================
    ws.sendkeys "{tab}"
    ws.sendkeys "^a"
    wscript.sleep 200
    ws.sendkeys onelinestr(1)  'display name
    
    ws.sendkeys "{tab}"
    ws.sendkeys "^a"
    wscript.sleep 200
    ws.sendkeys onelinestr(1)   'user number
    
    ws.sendkeys "{tab}"
    ws.sendkeys "^a"
    wscript.sleep 200
    ws.sendkeys onelinestr(1)   'auth id
    
    ws.sendkeys "{tab}"    
    wscript.sleep 200
    ws.sendkeys "^a"
    wscript.sleep 200            
    ws.sendkeys twolinestr(1)   'password
    
    ws.sendkeys "{tab}"
    wscript.sleep 200
    ws.sendkeys "^a"
    wscript.sleep 200
    ws.sendkeys threelinestr(1)   'proxy ip
    
    ws.sendkeys "{tab}"        'domain
    wscript.sleep 200
    ws.sendkeys "^a"
    wscript.sleep 200
    ws.sendkeys threelinestr(1)
    
    '=============保存===========
    ws.sendkeys "{tab 48}"
    wscript.sleep 500
    ws.sendkeys "{tab}"
    wscript.sleep 500
    ws.sendkeys "{enter}"
    wscript.sleep 1500
    '===============重启==========
    
    ws.sendkeys "{tab 18}"
    wscript.sleep 1000
    ws.sendkeys "{enter}"
    wscript.sleep 1000
    ws.sendkeys "{tab 2}"
    wscript.sleep 500
    ws.sendkeys "{enter}"
    wscript.sleep 1000
    
    if ws.appactivate("来自网页的消息") then 
    
        ws.sendkeys "{enter}"
        wscript.sleep 1000
        
        msgbox "配置已完成,设备正在重启,请耐心等待...",,"提示"
        
    else 
        msgbox "配置未成功,请重新检查配置!",,"提示"
        
    end if 

end function 

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>

这篇文章就介绍到这了,希望大家以后多多支持。

相关标签: VBS VOIP