设置IP.vbs

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each objNetAdapter in colNetAdapters
sip=objNetAdapter.IPAddress

'If sip(0)="192.168.15.44" Then                    '判断要替换的ip
'    strIPAddress = Array("192.168.15.39")        '替换ip
'    strSubnetMask = Array("255.255.255.0")        '修改子网掩码
'    strGateway = Array("192.168.15.1")            '修改网关
'Else
'    strIPAddress = Array("192.168.15.39")        '替换ip
'    strSubnetMask = Array("255.255.255.0")        '修改子网掩码
'    strGateway = Array("192.168.15.1")            '修改网关
'End If

strIPAddress = Array("192.168.15.39")        '修改ip
strSubnetMask = Array("255.255.255.0")        '修改子网掩码
strGateway = Array("192.168.15.1")            '修改网关

strGatewayMetric = Array(1)
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
WScript.Echo "The IP address has been changed as " & strIPAddress(0)
Else
WScript.Echo "The IP address could not be changed."
End If
Exit For    '只修改第一个网卡的设置
Next

  1. da shang
    donate-alipay
               donate-weixin weixinpay

发表评论↓↓