POPTEST老李分享修改dns ip的vbs代码
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 objectIf 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.QuitElse '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 IPsDNSserv = "111.111.111.111,222.222.222.222"' Ask if the DNS servers should be set or removediAction = MsgBox("Would you like to use DNS?", _ vbYesNoCancel+vbQuestion+vbApplicationModal, "DNS Toggle: " & DNSserv)' Cancel was selected - quit this scriptIf vbCancel = iAction Then WScript.QuitEnd IfstrComputer = "." ' This computer' Get the Script shell and WMI Service objectsSet objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")Set WshShell = WScript.CreateObject("WScript.Shell")' The registry key that hold the TCP/IP parametersRegkey = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\"' Enumerate all of the enabled network devicesSet 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 messageszTitle = ""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 IfMsgBox szMssg, vbInformation, szTitlePOPTEST老李分享修改dns ip的vbs代码的更多相关文章
- POPTEST老李分享session,cookie的安全性以及区别 1
POPTEST老李分享session,cookie的安全性以及区别 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程 ...
- POPTEST老李分享DOM解析XML之java
POPTEST老李分享DOM解析XML之java Java提供了两种XML解析器:树型解释器DOM(Document Object Model,文档对象模型),和流机制解析器SAX(Simple ...
- POPTEST老李分享session,cookie的安全性以及区别 3
如何查看服务器端输送到我们电脑中的这些Cookie信息: 点开IE浏览器或其他浏览器,在菜单栏中有工具选项,点开有InterNet选项: Cookie名称.来源.文件格式( ...
- POPTEST老李分享session,cookie的安全性以及区别 2
四,session和cookie谁更安全 就个人而言,我觉得session更安全一点,我以下几点看法. 1,如果session和cookie一样安全的话,二者就没有并要同时存在了,只要cookie就好 ...
- centos 修改DNS,网关,IP地址
1.CentOS 修改DNS 修改对应网卡的DNS的配置文件 # vi /etc/resolv.conf 修改以下内容 nameserver 8.8.8.8 #google域名服务器 nameser ...
- CentOS 设置网络(修改IP&修改网关&修改DNS)--update.14.08.15
自己电脑上装的虚拟机用桥接方式连接物理机,虚拟机重启后ip会发生变化,非常阻碍Xshell的连接和hosts指定的dns. 通过修改IP为static模式,保持IP不变. ============== ...
- ubuntu 修改静态IP和DNS
1.修改配置文件/etc/network/interfacesroot@ubuntu:~# sudo vi /etc/network/interfaces 添加以下内容:auto eth0 ...
- Linux下修改网卡IP、DNS和网关
Linux下修改网卡IP和网关 建议通过终端字符方式下来修改 一.修改IP地址 vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOO ...
- CentOS 网络设置修改 指定IP地址 DNS 网关(转)
CentOS 网络设置修改 指定IP地址 DNS 网关(实测 笔记) 环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G) 系统版本:Centos-6.5-x86_64 ...
随机推荐
- 游戏UI框架设计(二) : 最简版本设计
游戏UI框架设计(二) --最简版本设计 为降低难度决定先讲解一个最简版本,阐述UI框架的核心设计理念.这里先定义三个核心功能: 1:UI窗体的自动加载功能. 2:缓存UI窗体. 3:窗体生命周期(状 ...
- Android开发8:数据存储(二)——SQLite数据库和ContentProvider的使用
前言 啦啦啦各位小伙伴们许久不见了~学期末和过年期间自己忙着做其他事没能及时更新Android开发系列课程的博客,实在是罪过罪过~ 好啦~废话不多说,进入我们今天的主题.今天我们将和大家学习其他的数据 ...
- 剑指offer编程题Java实现——替换空格
题目描述 请实现一个函数,将一个字符串中的空格替换成"%20".例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. package ...
- 利用busybox制作根文件系统
实际项目中可以使用Buildroot制作根文件系统 1.busybox源码下载及配置 https://busybox.net/downloads/ 1.1.修改Makefile (1) ARCH = ...
- Sicily 1151 魔板
Constraints Time Limit: 1 secs, Memory Limit: 32 MB , Special Judge Description 魔板由8个大小相同方块组成,分别用涂上不 ...
- php根据用户输入单词,匹配相似单词
最近在使用一款app背单词的时候,会在某个单词下面,列出与之相类似的单词.于是我在想这个功能是如何做的,自己使用php版本,做了个简单的例子. 大致思路如下: 1.生成英文单词库,并将单词放置redi ...
- C++ 11和C++98相比有哪些新特性
此文是如下博文的翻译: https://herbsutter.com/elements-of-modern-c-style/ C++11标准提供了许多有用的新特性.这篇文章特别针对使C++11和C++ ...
- Selenium 使用过程遇到问题随笔
最近正在学习Selenium,自学是比较难的,也很感谢网络环境中,各位大大的博文帮助. 也希望在此能够记录一下从小白学习使用selenium测试的过程,也希望能对别人有所帮助. 关于环境部署,以及入门 ...
- Prince2学习有感:PRINCE2项目管理到底是什么?
2007年1月份,我加入了荷兰Irdeto(中国)有限公司.刚进入公司,我就结识了Prince2(受控环境下的项目管理),才知道Prince2是英国政府在政府项目中使用的项目管理标准. 这个标准早 ...
- struts.xml语法
<!-- 1. struts.xml配置常量, 用来覆盖struts.properties中的默认常量配置 一般情况下, 这个配置放在struts.xml中, 不要放在各个模块的xml中. co ...