Python WMI网络适配器配置参数问题[Windows 8.1] [Python 2.7] [WMI 1.4.9]

时间:2016-09-29 17:27:12

标签: python wmi

当我尝试这样做时

SetDynamicDNSRegistration(True)

它返回'68',我在MSDN WMI page上查找,这意味着“无效的输入参数”。

完整脚本

import wmi

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.151'
subnetmask = u'255.255.255.0'
gateway = u'192.168.0.1'
dns = u'192.168.0.1'

# Set IP address, subnetmask and default gateway
# Note: EnableStatic() and SetGateways() methods require *lists* of values to be passed
a = nic.EnableStatic(IPAddress=[ip],SubnetMask=[subnetmask])
b = nic.SetGateways(DefaultIPGateway=[gateway])
c = nic.SetDNSServerSearchOrder([dns])
d = nic.SetDynamicDNSRegistration(True)

print(a)
print(b)
print(c)
print(d)

有什么问题?我确定“True”是布尔值为TRUE的正确Python语法......我甚至不知道......

1 个答案:

答案 0 :(得分:1)

使用其对应的布尔整数,而不是Python布尔值。而不是

nic.SetDynamicDNSRegistration(True)

使用

nic.SetDynamicDNSRegistration(FullDNSRegistrationEnabled=1)