请选择 进入手机版 | 继续访问电脑版

VBS一键配置VOIP脚本代码

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

买目录提供泛目录、二级目录、租目录、出租网站建设资源、编程学习类,提供asp、php、asp.net、javascript、jquery、vbscript、dos批处理、网页制作、网络编程、网站建设等编程资料。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则