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. iOS开发之Runtime常用示例总结

    经常有小伙伴私下在Q上问一些关于Runtime的东西,问我有没有Runtime的相关博客,之前还真没正儿八经的总结过.之前只是在解析第三方框架源码时,聊过一些用法,也就是这些第三方框架中用到的Runt ...

  2. 关于 <textarea ></textarea >标签在苹果微信浏览器出现 内阴影

    解决方法:(去除浏览器默认的样式元素) textarea  { box-shadow:0px 0px 0px rgba(0,0,0,0); -webkit-appearance:none; }

  3. groovy hello world

    安装方法见官方文档http://groovy.codehaus.org/Installing+Groovy 用新一个文件HelloWorld.groovy,以utf8的编码保存,内容为: printl ...

  4. MONO 如何打包 .NET程序独立运行(winform篇)

    .NET程序独立运行是指运行.NET的电脑上,不需要安装.NET框架. .NET程序集“独立运行”并非真正的独立,它是运行在mono运行时基础之上的.由于这个运行时可以独立存在,所以,我们不需要在目标 ...

  5. python2.7读汉字的时候出现乱码,如何解决

    我使用的是window系统,安装Anaconda,所以用的是. 1.数据形式 2.读进来乱码 3.解决办法 3.1方法1 import pandas as pd #pd.read_csv('c:/us ...

  6. 如何把函数都用promise方式实现?

    如何把函数都用promise方式实现? 我觉得这是一个好问题.当前在我所在的公司,只要用 NodeJS 进行开发,从框架到具体的应用实例到工具,已经全部迁移到以 promise 为中心开发方式.带来的 ...

  7. 【数据标识】iOS App下载渠道的统计需求

    需求概述 我们现在有一个需求,某一个活动需要拉新所谓的拉新一般是推App下载,这个用户通过这个活动下载了App后,我们需要做到[在数据库中记录这个用户下载这个App是通过那个二维码渠道的,从效果上说, ...

  8. 利用自动类型转换存储string类型

    类型转换是我们最常用的功能.就像上战场用的枪一样,敌人用的冲锋枪, 自己手里就一把步枪,打起仗来始终有点不爽. 因此,基本功能的完善很重要. 通常情况下我们需要String类型转其它的基础类型.这时我 ...

  9. nginx配置参数详解

    配置参数详解 user nginx nginx ; Nginx用户及组:用户 组.window下不指定 worker_processes 8; 工作进程:数目.根据硬件调整,通常等于CPU数量或者2倍 ...

  10. C++:基础篇-32位和64位系统区别及字节数

    今儿面试了一个刚刚毕业的,但是不知道一个int.long.double这几个都是多少位,我给你们总结一下哈: 常用数据类型对应字节数  可用如sizeof(char),sizeof(char*)等得出 ...