求一个bat文件用来改ip及主备dns

2024-11-22 09:55:03
推荐回答(3个)
回答1:

netsh interface ip set dns name="本地连接" source=static addr=202.96.69.38 register=primary
netsh interface ip add dns name="本地连接" addr=202.96.64.68 index=2
备用DNS不用加static,后面加index=2指明他是第二个DNS
具体可以在CMD下输入netsh后使用?查看
netsh interface ip>add dns ?

设置IP脚本可以参考下面链接:

回答2:

以下是保定网通的改IP及主备DNS你把 网关地址改成你的就好 把以下用记事本打开另存为 .vbs

Dim return,return2,AAA,STR,counter
Dim STR_NEWDNS1,STR_NEWDNS2,STR_GATEWAY,arrIPAddress,arrSubnetMask
Set R = CreateObject("WScript.Shell")
return=MsgBox ("网关是 192.168.0.1 吗?点是",vbyesno+vbexclamation,"网关地址选择")
If return=vbyes Then
STR_GATEWAY = "192.168.0.1"
else
return=MsgBox ("网关是 192.168.1.1 吗?点否",vbyesno+vbexclamation,"网关地址选择")
If return=vbyes Then
STR_GATEWAY = "192.168.1.1"
else
Num=Inputbox ("请输入网关:","修改网关地址")
STR_GATEWAY = Num
if Num="" then wscript.quit
end if
End if

AAA=InStr(STR_GATEWAY,".")
AAA=InStr(AAA+1,STR_GATEWAY,".")
AAA=InStr(AAA+1,STR_GATEWAY,".")
STR=mid(STR_GATEWAY,1,AAA)

Do
Randomize Timer
counter = Fix(Rnd * 254 - 1)
Loop While counter<2 or counter>253
arrIPAddress = STR+cstr(counter)

STR_NEWDNS1 = "202.99.166.4"
STR_NEWDNS2 = "202.99.160.68"
return=MsgBox ("是不是网通的网络?点是",vbyesno+vbexclamation,"DNS服务器地址选择")
If return=vbno Then

end if

arrSubnetMask = "255.255.255.0"

Set fs=CreateObject("Scripting.FileSystemObject")
strWinMgmt="winmgmts:{impersonationLevel=impersonate}"
Set objNICs = GetObject( strWinMgmt ).InstancesOf("Win32_NetworkAdapterConfiguration")
For Each objNIC In objNICs
If objNIC.IPEnabled Then
objNIC.SetDNSServerSearchOrder Array(STR_NEWDNS1,STR_NEWDNS2)
objNIC.SetGateways Array(STR_GATEWAY)
errEnableStatic=objNIC.EnableStatic(Array(arrIPAddress), Array(arrSubnetMask))
End If
Next

list = "IP地址:" & arrIPAddress & vbCr
list = list & "掩码为:" & arrSubnetMask & vbCr
list = list & "网关地址:" & STR_GATEWAY & vbCr
list = list & "首选DNS:" & STR_NEWDNS1 & vbCr
list = list & "次要DNS:" & STR_NEWDNS2 & vbCr

回答3:

netsh interface ip set address name="本地连接" source=static gateway=192.168.0.1 gwmetric=1

netsh interface ip set dns name="本地连接" source=static addr=192.168.0.1 register=primary

看下上面两个,然后对比你自己的,就可以找到什么地方有问题的了