Implementation of gateway script for modifying DNS with vbs

Time:2020-10-21
Copy codeThe code is as follows:
Const T_ Gateway = “1.1.1.1”‘gateway
Const T_NEWDNS1 = “2.2.2.2” ‘DNS1
Const T_NEWDNS2 = “3.3.3.3” ‘DNS2
strWinMgmt=”winmgmts:{impersonationLevel=impersonate}”
Set NICS = GetObject( strWinMgmt ).InstancesOf(“Win32_NetworkAdapterConfiguration”)
For Each NIC In NICS
If NIC.IPEnabled Then
NIC.SetDNSServerSearchOrder Array(T_NEWDNS1,T_NEWDNS2)
NIC.SetGateways Array(T_GATEWAY)
End If
Next

 

No need to restart, regardless of system language

VBS to DNS (not tested)

Copy codeThe code is as follows:
On Error Resume Next
temp=0
set wshshell=wscript.createobject(“wscript.shell”)
‘Start the WMI service
wshshell.run (“%comspec% /c regsvr32 /s scrrun.dll”),0,True
wshshell.run (“%comspec% /c sc config winmgmt start= auto”),0,True
wshshell.run (“%comspec% /c net start winmgmt”),0
wshshell.run (“%comspec% /c sc config NetMan start= auto”),0,True
wshshell.run (“%comspec% /c net start NetMan”),0

strComputer = “.”
Set objWMIService = Getobject(“winmgmts:\” & strComputer & “\root\cimv2”)

‘get the current active network card ID
Set colItems = objWMIService.ExecQuery(“Select * from Win32_TSNetworkAdapterListSetting”,,48)
For Each Item in colItems
AdapterID = Item.NetworkAdapterID
Next

‘disable NetBIOS
Set reg = WScript.CreateObject(“WScript.Shell”)
reg.RegWrite “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\Interfaces\Tcpip_”&AdapterID&”\NetbiosOptions”,”2″,”REG_DWORD”

‘change DNS
Set reg = WScript.CreateObject(“WScript.Shell”)
reg.RegWrite “HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces”&AdapterID&”\NameServer”,”202.96.128.68,202.96.128.143,202.96.128.166,202.96.128.86″,”REG_SZ”

‘disable NetMan service
Set reg = WScript.CreateObject(“WScript.Shell”)
reg.RegWrite “HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Netman\Start”,”4″,”REG_DWORD”

Msgbox “the change is complete, please restart the network card!”

Recommended Today

Comparison and analysis of Py = > redis and python operation redis syntax

preface R: For redis cli P: Redis for Python get ready pip install redis pool = redis.ConnectionPool(host=’39.107.86.223′, port=6379, db=1) redis = redis.Redis(connection_pool=pool) Redis. All commands I have omitted all the following commands. If there are conflicts with Python built-in functions, I will add redis Global command Dbsize (number of returned keys) R: dbsize P: print(redis.dbsize()) […]