经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » ASP/ADO/VBScript » 查看文章
VBS一键配置VOIP脚本代码
来源:jb51  时间:2019/9/29 8:38:45  对本文有异议

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

  1. Dimws,fso,IE
  2. SetIE = WScript.createobject("InternetExplorer.Application")
  3. Setws = WScript.CreateObject ("WSCript.shell")
  4. Setfso=CreateObject("scripting.filesystemobject")
  5.  
  6. Constreboot="/content.cgi?form=M_SAV"
  7.  
  8. IE.menubar=0'显示IE对象菜单栏
  9. IE.AddressBar=1 '显示IE对象地址栏
  10. IE.ToolBar=0'显示IE对象工具栏
  11. IE.StatusBar=1 '不显示IE对象状态栏
  12. IE.FullScreen=0'全屏化IE对象
  13. IE.Height=768
  14. IE.Width=1024
  15. IE.Resizable=1 '设置IE对象大小是否可以被改动
  16. IE.visible=1'设置是否可见 
  17.  
  18. 'IE.Navigate"192.168.46.3"
  19.  
  20.  
  21. '==============读Config配置文件=========
  22.     
  23. filepath=createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path
  24. file_config=filepath&"\config.ini"
  25. Set file=fso.OpenTextFile(file_config,1)
  26.     
  27. '===========取第一行数据:号码==============
  28. OneLine=file.ReadLine
  29. OneLineStr=Split(OneLine,"=")
  30. OneLineCount=UBound(split(OneLine,"="))
  31. 'MsgBox OneLineStr(1)                   
  32.  
  33.     
  34. '===============取第二行数据:密码===========
  35. TwoLine=file.ReadLine
  36. TwoLineStr=Split(TwoLine,"=")
  37. TwoLineCount=UBound(split(TwoLine,"="))
  38. 'MsgBox TwoLineStr(1)
  39.     
  40. '===============取第三行数据:VOIP服务地址============
  41. ThreeLine=file.ReadLine
  42. ThreeLineStr=Split(ThreeLine,"=")
  43. ThreeLineCount=UBound(split(ThreeLine,"="))
  44. 'MsgBox ThreeLineStr(1)
  45.     
  46. '===============取第四行数据:对讲设备地址============
  47. FourLine=file.ReadLine
  48. FourLineStr=Split(FourLine,"=")
  49. FourLineCount=UBound(split(FourLine,"="))
  50. 'MsgBox FourLineStr(1)
  51.     
  52. '===============取第五行数据:浏览器安装目录============
  53. FiveLine=file.ReadLine
  54. FiveLineStr=Split(FiveLine,"=")
  55. FiveLineCount=UBound(split(FiveLine,"="))
  56. 'MsgBox FiveLineStr(1)
  57.     
  58. 'MainWeb()
  59.  
  60. Main()
  61. '==================================================
  62.  
  63. Function Main()
  64.  
  65.     IE.Navigate FourLineStr(1)
  66.         
  67.     Do 
  68.         WScript.Sleep 500
  69.         
  70.     Loop Until IE.ReadyState=4
  71.     
  72.     
  73.     Login()
  74.     SipSetting()
  75.     InputParm()
  76.     VOIP()
  77.     RebootSys()
  78.  
  79. End Function 
  80. '======================================================
  81. '登录系统
  82. Function Login()
  83.  
  84.     WScript.Sleep 1000
  85.     ws.SendKeys "^a"
  86.     WScript.Sleep 200
  87.     ws.SendKeys "admin"
  88.     ws.SendKeys "{TAB}"
  89.     ws.SendKeys "^a"
  90.     WScript.Sleep 200
  91.     ws.SendKeys "admin"
  92.     ws.SendKeys "{TAB}"
  93.     WScript.Sleep 200
  94.     ws.SendKeys "{ENTER}"
  95.  
  96. End Function 
  97. '================================================
  98. '进入sipsetting菜单
  99. Function SipSetting()
  100.  
  101.     If IE.ReadyState=4 Then 
  102.     
  103.         WScript.Sleep 1000
  104.         ws.SendKeys "{TAB 5}"
  105.         WScript.Sleep 500
  106.         ws.SendKeys "{ENTER}"
  107.         WScript.Sleep 500
  108.         ws.SendKeys "{TAB}"
  109.         WScript.Sleep 500
  110.         ws.SendKeys "{ENTER}"
  111.         WScript.Sleep 2000
  112.     Else 
  113.     
  114.      MsgBox "进入配置界面失败!"
  115.      
  116.     End If 
  117.  
  118. End Function 
  119. '=============================================
  120. '切换输入界面
  121. Function InputParm()
  122.  
  123.     ws.SendKeys "{TAB}"
  124.     WScript.Sleep 200
  125.     ws.SendKeys "{TAB}"
  126.     WScript.Sleep 200
  127.     ws.SendKeys "{TAB}"
  128.     WScript.Sleep 200
  129.     ws.SendKeys "{TAB}"
  130.     WScript.Sleep 200
  131.     ws.SendKeys "{TAB}"
  132.     WScript.Sleep 200
  133.     ws.SendKeys "{TAB}"
  134.     WScript.Sleep 200
  135.     ws.SendKeys "{TAB}"
  136.     WScript.Sleep 200
  137.     ws.SendKeys "{TAB}"
  138.     WScript.Sleep 200
  139.     ws.SendKeys "{TAB}"
  140.     WScript.Sleep 200    
  141.     ws.SendKeys "{TAB}"
  142.     WScript.Sleep 200
  143.     ws.SendKeys "{TAB}"
  144.     WScript.Sleep 200
  145.     ws.SendKeys "{TAB}"
  146.     WScript.Sleep 200
  147.     
  148.     
  149.     ws.SendKeys "{DOWN}"  '选择开启状态
  150.     WScript.Sleep300
  151.  
  152. EndFunction
  153. '=========================================
  154. '配置参数
  155. FunctionVOIP()
  156.  
  157.     ws.SendKeys"{TAB}"
  158.     ws.SendKeys"^a"
  159.     WScript.Sleep200
  160.     ws.SendKeysOneLineStr(1)  'display name
  161.     
  162.     ws.SendKeys "{TAB}"
  163.     ws.SendKeys "^a"
  164.     WScript.Sleep 200
  165.     ws.SendKeys OneLineStr(1)   'usernumber
  166.     
  167.     ws.SendKeys"{TAB}"
  168.     ws.SendKeys"^a"
  169.     WScript.Sleep200
  170.     ws.SendKeysOneLineStr(1)   'auth id
  171.     
  172.     ws.SendKeys "{TAB}"    
  173.     WScript.Sleep 200
  174.     ws.SendKeys "^a"
  175.     WScript.Sleep 200            
  176.     ws.SendKeys TwoLineStr(1)   'password
  177.     
  178.     ws.SendKeys"{TAB}"
  179.     WScript.Sleep200
  180.     ws.SendKeys"^a"
  181.     WScript.Sleep200
  182.     ws.SendKeysThreeLineStr(1)   'proxy ip
  183.     
  184.     ws.SendKeys "{TAB}"        'domain
  185.     WScript.Sleep200
  186.     ws.SendKeys"^a"
  187.     WScript.Sleep200
  188.     ws.SendKeysThreeLineStr(1)
  189.     
  190.     '=============保存===========
  191.     ws.SendKeys "{TAB 48}"
  192.     WScript.Sleep 500
  193.     ws.SendKeys "{TAB}"
  194.     WScript.Sleep 500
  195.     ws.SendKeys "{ENTER}"
  196.     WScript.Sleep 1500
  197.     
  198. End Function 
  199.  
  200. '========================================================
  201. '修改参数后重启
  202. Function RebootSys()
  203.  
  204.     WScript.Sleep 500
  205.     ws.SendKeys "{F4}"
  206.     WScript.Sleep 500
  207.     ws.SendKeys "^a"
  208.     WScript.Sleep 200
  209.     ws.SendKeys FourLineStr(1)&reboot 
  210.     
  211.     WScript.Sleep 500    
  212.     
  213. '   Settest=IE.document.getElementsByTagName ("Button")
  214.     ws.SendKeys"{ENTER}"
  215.     
  216.     WScript.Sleep2000
  217.     
  218.     SetALL = Ie.Document.getElementsByTagName("input")  '检测网页元素是否标签为input,且值等于Reboot
  219.  
  220.     For Each i In ALL
  221.  
  222.     If i.value="Reboot" Then
  223.  
  224.        'i.Click  '点击reboot按钮
  225.        
  226.         WScript.Sleep 1000
  227.        
  228.         Ie.Document.parentwindow.execScript("top.location='content.cgi?_method_=reboot'")  '直接执行reboot确认操作
  229.  
  230.         ExitFor
  231.  
  232.      
  233.     EndIf
  234.  
  235.     Next
  236.     
  237.     WScript.Sleep3000    
  238.     
  239.     MsgBox"配置已完成,设备正在重启,请耐心等待...",,"提示"
  240.  
  241.     Ifws.AppActivate("来自网页的消息") Then
  242.     
  243.     
  244.         ws.SendKeys"{ENTER}"
  245.         WScript.Sleep2000
  246.         
  247.         MsgBox"配置已完成,设备正在重启,请耐心等待...",,"提示"
  248.         
  249.     Else
  250.         'MsgBox "配置未成功,请重新检查配置!",,"提示"
  251.         
  252.     End If 
  253.  
  254. End Function 
  255.  
  256.  
  257. '====================================================================
  258.  
  259. FunctionMainWeb()
  260.  
  261.     '=============启动地址=====================
  262. '方式一:自定义浏览器启动,需配置路径
  263. '   Function login()
  264.         
  265. '       ws.runFiveLineStr(1)
  266. '       WScript.Sleep 3000
  267. '       ws.SendKeys"{F4}"
  268. '       WScript.Sleep 200
  269. '       ws.SendKeys"^a"
  270. '       WScript.Sleep 500
  271. '       ws.SendKeysFourLineStr(1)
  272. '       WScript.Sleep 500
  273. '       ws.SendKeys"{ENTER}"
  274.                 
  275. '   End Function    
  276.  
  277. '方式二:用系统默认浏览器启动 
  278.     ws.RunFourLineStr(1)
  279.  
  280.     '===============登录设备=====================
  281.     WScript.Sleep 5000
  282.     ws.SendKeys "^a"
  283.     WScript.Sleep 200
  284.     ws.SendKeys "admin"
  285.     ws.SendKeys "{TAB}"
  286.     ws.SendKeys "^a"
  287.     WScript.Sleep 200
  288.     ws.SendKeys "admin"
  289.     ws.SendKeys "{ENTER}"
  290.     
  291.     '============进入sipsetting菜单=============
  292.     WScript.Sleep2000
  293.     ws.SendKeys"{TAB 5}"
  294.     WScript.Sleep500
  295.     ws.SendKeys"{ENTER}"
  296.     WScript.Sleep500
  297.     ws.SendKeys"{TAB}"
  298.     WScript.Sleep500
  299.     ws.SendKeys"{ENTER}"
  300.     WScript.Sleep2000
  301.     
  302.     
  303.     '==============进入编辑状态=======================
  304.     ws.SendKeys "{TAB}"
  305.     WScript.Sleep 200
  306.     ws.SendKeys "{TAB}"
  307.     WScript.Sleep 200
  308.     ws.SendKeys "{TAB}"
  309.     WScript.Sleep 200
  310.     ws.SendKeys "{TAB}"
  311.     WScript.Sleep 200
  312.     ws.SendKeys "{TAB}"
  313.     WScript.Sleep 200
  314.     ws.SendKeys "{TAB}"
  315.     WScript.Sleep 200
  316.     ws.SendKeys "{TAB}"
  317.     WScript.Sleep 200
  318.     ws.SendKeys "{TAB}"
  319.     WScript.Sleep 200
  320.     ws.SendKeys "{TAB}"
  321.     WScript.Sleep 200    
  322.     ws.SendKeys "{TAB}"
  323.     WScript.Sleep 200
  324.     ws.SendKeys "{TAB}"
  325.     WScript.Sleep 200
  326.     ws.SendKeys "{TAB}"
  327.     WScript.Sleep 200
  328.     
  329.     
  330.     
  331.     ws.SendKeys "{DOWN}"  '选择开启状态
  332.     WScript.Sleep300
  333.  
  334.     
  335.     '==============配置VOIP================
  336.     ws.SendKeys "{TAB}"
  337.     ws.SendKeys "^a"
  338.     WScript.Sleep 200
  339.     ws.SendKeys OneLineStr(1)  'displayname
  340.     
  341.     ws.SendKeys"{TAB}"
  342.     ws.SendKeys"^a"
  343.     WScript.Sleep200
  344.     ws.SendKeysOneLineStr(1)   'user number
  345.     
  346.     ws.SendKeys "{TAB}"
  347.     ws.SendKeys "^a"
  348.     WScript.Sleep 200
  349.     ws.SendKeys OneLineStr(1)   'authid
  350.     
  351.     ws.SendKeys"{TAB}"    
  352.     WScript.Sleep200
  353.     ws.SendKeys"^a"
  354.     WScript.Sleep200            
  355.     ws.SendKeysTwoLineStr(1)   'password
  356.     
  357.     ws.SendKeys "{TAB}"
  358.     WScript.Sleep 200
  359.     ws.SendKeys "^a"
  360.     WScript.Sleep 200
  361.     ws.SendKeys ThreeLineStr(1)   'proxyip
  362.     
  363.     ws.SendKeys"{TAB}"        'domain
  364.     WScript.Sleep 200
  365.     ws.SendKeys "^a"
  366.     WScript.Sleep 200
  367.     ws.SendKeys ThreeLineStr(1)
  368.     
  369.     '=============保存===========
  370.     ws.SendKeys"{TAB 48}"
  371.     WScript.Sleep500
  372.     ws.SendKeys"{TAB}"
  373.     WScript.Sleep500
  374.     ws.SendKeys"{ENTER}"
  375.     WScript.Sleep1500
  376.     '===============重启==========
  377.     
  378.     ws.SendKeys "{TAB 18}"
  379.     WScript.Sleep 1000
  380.     ws.SendKeys "{ENTER}"
  381.     WScript.Sleep 1000
  382.     ws.SendKeys "{TAB 2}"
  383.     WScript.Sleep 500
  384.     ws.SendKeys "{ENTER}"
  385.     WScript.Sleep 1000
  386.     
  387.     If ws.AppActivate("来自网页的消息") Then 
  388.     
  389.         ws.SendKeys "{ENTER}"
  390.         WScript.Sleep 1000
  391.         
  392.         MsgBox "配置已完成,设备正在重启,请耐心等待...",,"提示"
  393.         
  394.     Else 
  395.         MsgBox "配置未成功,请重新检查配置!",,"提示"
  396.         
  397.     End If 
  398.  
  399. End Function 
  400.  
  401. Set ws=Nothing 
  402. Set IE=Nothing 
  403. 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> </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>

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

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号