python 修改ip地址

安装包

pip install wmi
pip install pywin32

 

实现

import wmi

# Obtain network adaptors configurations
nic_configs = wmi.WMI().Win32_NetworkAdapterConfiguration(IPEnabled=True)
print(nic_configs);
# First network adaptor
nic = nic_configs[0]
print(nic);
# IP address, subnetmask and gateway values should be unicode objects
ip = u'192.168.1.12'
subnetmask = u'255.255.255.0'
#gateway = u'192.168.1.1'   

#如果不设网关gateway放ip地址得值就可以

# Set IP address, subnetmask and default gateway
# Note: EnableStatic() and SetGateways() methods require *lists* of values to be passed
print(3);
nic.EnableStatic(IPAddress=[ip],SubnetMask=[subnetmask])
print(4);
#nic.SetGateways(DefaultIPGateway=[gateway])

 

你可能感兴趣的:(Python)