Update win_dns_client.py

If there is no dns address setted in the windows client, the iface_config.DNSServerSearchOrder method will return None, therefore this module will generate TypeError,  'NoneType' object is not iterable.
This commit is contained in:
Damon Zheng 2015-08-26 09:49:39 +08:00
parent 4450432161
commit 1a45db0fb7

View file

@ -45,7 +45,10 @@ def get_dns_servers(interface='Local Area Connection'):
for iface in c.Win32_NetworkAdapter(NetEnabled=True):
if interface == iface.NetConnectionID:
iface_config = c.Win32_NetworkAdapterConfiguration(Index=iface.Index).pop()
return list(iface_config.DNSServerSearchOrder)
+ try:
+ return list(iface_config.DNSServerSearchOrder)
+ except:
+ return []
log.debug('Interface "{0}" not found'.format(interface))
return False