import wmi
# Obtain network adaptors configurations
nic_configs = wmi.WMI().Win32_NetworkAdapterConfiguration(IPEnabled=True)
# First network adaptor
nic = nic_configs[0]
# IP address, subnetmask and gateway values should be unicode objects
ip = u'192.168.0.11'
subnetmask = u'255.255.255.0'
gateway = u'192.168.0.1'
# Set IP address, subnetmask and default gateway
# Note: EnableStatic() and SetGateways() methods require *lists* of values to be passed
nic.EnableStatic(IPAddress=[ip],SubnetMask=[subnetmask])
nic.SetGateways(DefaultIPGateway=[gateway])
============================================================
#Here is how to revert to obtaining an IP address automatically (via DHCP):
import wmi
# Obtain network adaptors configurations
nic_configs = wmi.WMI().Win32_NetworkAdapterConfiguration(IPEnabled=True)
# First network adaptor
nic = nic_configs[0]
# Enable DHCP
nic.EnableDHCP()
'Analysis > Python' 카테고리의 다른 글
[Python] with, seek, tell (0) | 2016.08.03 |
---|---|
Python 리스트(배열) (0) | 2016.07.05 |
Python Random 함수 (0) | 2016.07.05 |
base64로 인코딩된 바이너리 파일 확인 (0) | 2016.03.31 |