批处理自动更改公司或家里IP地址切换上网VBS脚本
a=msgbox("是否改变为家里上网的IP"& Chr(13) &"是,改成家里的"& Chr(13) &"否,改成公司的"& Chr(13) &"取消不改变IP"& Chr(13) & Chr(10) & Chr(10) &" 制作:whatask",3,"改变IP")
if a=6 then
strIP = "192.168.1.XX" 'ip
strMask = "255.255.255.0" '掩码
strGW = "192.168.1.1" '网关
strDNS1 = "202.102.154.3" 'dns
strDNS2 = "202.102.152.3" 'dns
strComputer = "."
Set objWMIService = GetObject("winmgmts:\" & strComputer & "rootcimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array(strIP)
strSubnetMask = Array(strMask)
strGateway = Array(strGW)
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
arrDNSServers = Array(strDNS1,strDNS2)
errDNS = objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)
If errEnable = 0 Then
WScript.Echo "已成功更改成家里上网的IP。"
Else
WScript.Echo "更改IP地址失败。"
End If
Next
elseif a=7 then
strIP = "192.168.1.XX" 'ip
strMask = "255.255.255.0" '掩码
strGW = "192.168.1.1" '网关
strDNS1 = "202.102.154.3" 'dns
strDNS2 = "202.102.152.3" 'dns
strComputer = "."
Set objWMIService = GetObject("winmgmts:\" & strComputer & "rootcimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array(strIP)
strSubnetMask = Array(strMask)
strGateway = Array(strGW)
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
arrDNSServers = Array(strDNS1,strDNS2)
errDNS = objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)
If errEnable = 0 Then
WScript.Echo "已成功更改成公司上网的IP。"
Else
WScript.Echo "更改IP地址失败。"
End If
Next
elseif a=2 then
msgbox "IP地址没有改变"
end if
另存为XX.VBS文件,
上面第一段IP 就是家里的,你自己修改一下IP、网关、DNS就行,
第二段就是公司的,也改成相应的,没有就不写。
以后只要双击这个文件就行了。
评论前必须登录!
注册