日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2024/4/14 编程问答 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POPTEST老李分享修改dns ip的vbs代码 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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

poptest是國(guó)內(nèi)唯一一家培養(yǎng)測(cè)試開(kāi)發(fā)工程師的培訓(xùn)機(jī)構(gòu),以學(xué)員能勝任自動(dòng)化測(cè)試,性能測(cè)試,測(cè)試工具開(kāi)發(fā)等工作為目標(biāo)。如果對(duì)課程感興趣,請(qǐng)大家咨詢(xún)qq:908821478,咨詢(xún)電話(huà)010-84505200。

? ?準(zhǔn)備把學(xué)員在工作中寫(xiě)的一個(gè)自動(dòng)化功能加入到培訓(xùn)中案例,由于測(cè)試服務(wù)器功能,每次要修改ip地址,所以要自動(dòng)化去修改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

轉(zhuǎn)載于:https://www.cnblogs.com/poptest/p/5210592.html

總結(jié)

以上是生活随笔為你收集整理的POPTEST老李分享修改dns ip的vbs代码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。