一个可以自动更改IP地址的脚本

怎么说呢?其实改IP有很多方法,利用上篇文章中的netsh 命令做个批处理命令也可以做到。有兴趣的自己研究研究吧,下面的使用VBS做的。其实偶只是单纯的复制粘贴,代码还可以精简点的哦。

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array("12.113.47.50")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("12.113.47.1")
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
    errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
    errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
    If errEnable = 0 Then
        WScript.Echo "The IP address has been changed."
    Else
        WScript.Echo "The IP address could not be changed."
    End If
Next

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
    arrDNSServers = Array("12.113.250.253", "12.113.250.254")
    objNetCard.SetDNSServerSearchOrder(arrDNSServers)
Next

汉堡加盟http://www.fanzaihanbao.com/汉堡店加盟

你可能感兴趣的:(一个可以自动更改IP地址的脚本)