编程语言
首页 > 编程语言> > python 修改ip地址

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,ip,wmi,地址,nic,print,subnetmask,gateway
来源: https://blog.csdn.net/csharp25/article/details/104861855