POPTEST老李分享修改dns ip的vbs代码

 

poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标。如果对课程感兴趣,请大家咨询qq:908821478,咨询电话010-84505200。

准备把学员在工作中写的一个自动化功能加入到培训中案例,由于测试服务器功能,每次要修改ip地址,所以要自动化去修改dns ip,代码如下:

' This script changes the DNS servers for a network device in Windows
' to a defined IP or deletes them and makes it the default automatic
 
' Test if in admin mode by detecting 'elevated' in the command line that launched this script
' WScript is basically a THIS script object
 
If WScript.Arguments.Named.Exists("elevated") = False Then
    'Launch this script again as administrator
    CreateObject _
     ("Shell.Application").ShellExecute _
        "wscript.exe""""" & WScript.ScriptFullName & """ /elevated""""runas", 1
    WScript.Quit
Else
    'Change the working directory from the system32 folder back to the script's folder.
    Set oShell = CreateObject("WScript.Shell")
    oShell.CurrentDirectory = CreateObject _
        ("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
    'MsgBox "Now running with elevated permissions"
End If
 
' Define the DNS Primary and secondary server IPs
DNSserv = "111.111.111.111,222.222.222.222"
 
' Ask if the DNS servers should be set or removed
iAction = MsgBox("Would you like to use DNS?", _
        vbYesNoCancel+vbQuestion+vbApplicationModal, "DNS Toggle: " & DNSserv)
 
' Cancel was selected - quit this script
If vbCancel = iAction Then
    WScript.Quit
End If
 
strComputer = "." ' This computer
 
' Get the Script shell and WMI Service objects
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set WshShell = WScript.CreateObject("WScript.Shell")
 
' The registry key that hold the TCP/IP parameters
Regkey = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\"
 
' Enumerate all of the enabled network devices
Set IPDevSet = objWMIService.ExecQuery _
("Select SettingID from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
 
DNSservRead = ""
 
For Each IPDev in IPDevSet
    ' Get the current setting
    DNSservRead = WshShell.RegRead _
        ( Regkey & IPDev.SettingID & "\NameServer")
    'MsgBox "DNS Servers was set to:"  & vbCrLf & DNSservRead, vbOK, "Old Status"
 
    ' if it's blank and the user chose YES set it to the DNS Server values.
    ' So we don't overwrite the values that are already set
    If "" = DNSservRead and vbYes = iAction Then
        'Combine regkey, settingID, and nameserver to create the correct registry key path
        WshShell.RegWrite Regkey & IPDev.SettingID & "\NameServer", DNSserv, "REG_SZ"
         
    ' If the user selected NO to delete the DNS values this script sets
    ' and it's not set to those DNS values do not mess with it.
    ElseIf DNSservRead = DNSServ and vbNo = iAction Then
        WshShell.RegWrite Regkey & IPDev.SettingID & "\NameServer""""REG_SZ"
    End If
 
    ' See the new setting
    'DNSservRead = WshShell.RegRead( Regkey & IPDev.SettingID & "\NameServer")
    'MsgBox "DNS Servers now set to:"  & vbCrLf & DNSservRead, vbOK, "New Status"
Next
 
'Final message
szTitle = ""
szMssg = ""
If vbYes = iAction Then
    szMssg = "DNS Servers now set to use:" & vbCrLf & " " & DNSserv
    szTitle = "DNS.com is ON"
Else
    szMssg = "DNS Servers deleted."& vbCrLf & "Now set to Automatic"
    szTitle = "DNS.com is OFF"
End If
 
MsgBox szMssg, vbInformation, szTitle

POPTEST老李分享修改dns ip的vbs代码的更多相关文章

  1. POPTEST老李分享session,cookie的安全性以及区别 1

    POPTEST老李分享session,cookie的安全性以及区别   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程 ...

  2. POPTEST老李分享DOM解析XML之java

    POPTEST老李分享DOM解析XML之java   Java提供了两种XML解析器:树型解释器DOM(Document Object Model,文档对象模型),和流机制解析器SAX(Simple ...

  3. POPTEST老李分享session,cookie的安全性以及区别 3

    如何查看服务器端输送到我们电脑中的这些Cookie信息:      点开IE浏览器或其他浏览器,在菜单栏中有工具选项,点开有InterNet选项:          Cookie名称.来源.文件格式( ...

  4. POPTEST老李分享session,cookie的安全性以及区别 2

    四,session和cookie谁更安全 就个人而言,我觉得session更安全一点,我以下几点看法. 1,如果session和cookie一样安全的话,二者就没有并要同时存在了,只要cookie就好 ...

  5. centos 修改DNS,网关,IP地址

    1.CentOS 修改DNS 修改对应网卡的DNS的配置文件 # vi /etc/resolv.conf  修改以下内容 nameserver 8.8.8.8 #google域名服务器 nameser ...

  6. CentOS 设置网络(修改IP&修改网关&修改DNS)--update.14.08.15

    自己电脑上装的虚拟机用桥接方式连接物理机,虚拟机重启后ip会发生变化,非常阻碍Xshell的连接和hosts指定的dns. 通过修改IP为static模式,保持IP不变. ============== ...

  7. ubuntu 修改静态IP和DNS

    1.修改配置文件/etc/network/interfacesroot@ubuntu:~# sudo vi /etc/network/interfaces 添加以下内容:auto eth0       ...

  8. Linux下修改网卡IP、DNS和网关

    Linux下修改网卡IP和网关 建议通过终端字符方式下来修改 一.修改IP地址 vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOO ...

  9. CentOS 网络设置修改 指定IP地址 DNS 网关(转)

    CentOS 网络设置修改 指定IP地址 DNS 网关(实测 笔记)   环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G) 系统版本:Centos-6.5-x86_64 ...

随机推荐

  1. [java多线程] - 锁机制&同步代码块&信号量

    在美眉图片下载demo中,我们可以看到多个线程在公用一些变量,这个时候难免会发生冲突.冲突并不可怕,可怕的是当多线程的情况下,你没法控制冲突.按照我的理解在java中实现同步的方式分为三种,分别是:同 ...

  2. 为什么使用enable_shared_from_this——shared_ptr两类错误

    在使用C++实现弱回调时,订阅者应当维护一系列发布者的weak_ptr,而发布者注册回调时要传出this的shared_ptr指针,流行的实现方法是使用std::enable_shared_from_ ...

  3. TCP协议详解

    TCP协议详解 一.TCP协议 1.TCP 通过以下方式提供可靠性: ·  ◆ 应用程序分割为TCP认为最合适发送的数据块.由TCP传递给IP的信息单位叫做报文段. ·  ◆ 当TCP发出一个报文段后 ...

  4. BDD框架:behave学习记录

    本人学习的时候基本上是按照behave的tutorial教程一步步学习的,这篇文章就当Behave教程的翻译版吧(*^__^*) 嘻嘻--. 1         安装behave 安装好python后 ...

  5. 5_jQuery选择器

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/stric ...

  6. 漂亮的代码3:flatten 一个数组

    看到一个题目: flatten([1,2,3]) // => [1,2,3] flatten([[1,2,3],["a","b","c" ...

  7. 学习笔记——Java数字处理类

    1.数字格式化 使用Java.text.DecimalFormat格式化数字,一般使用其中的DecimalFormat类.如: import java.text.DecimalFormat; publ ...

  8. [转]支持向量机SVM总结

    首先,对于支持向量机(SVM)的简单总结: 1. Maximum Margin Classifier 2. Lagrange Duality 3. Support Vector 4. Kernel 5 ...

  9. Synchronize执行过程

    Synchronize执行过程及原理 在windows原生应用程序开发中,经常伴随多线程的使用,多线程开发很简单,难点就是在于线程的同步,在Delphi中提供了VC中不具备的一个过程Synchroni ...

  10. angular : direative : scope | 指令scope和transclude的关系

    今天记入的是指令的scope和transclude关系 a 和 b 都是指令 <div a> <div b></div> </div> a transc ...