dnspython currently uses the presence of "NTEContextList" to determine
whether a network card is enabled in Windows.
Vista no longer uses NTEContextList (whatever it is...), so dnspython
currently assumes that all the NICs are disabled, and never extracts
the DNS servers.
So I was playing around with a registry monitor, and managed to create
with a function which can determine whether a NIC is enabled or not.
It works for me on Vista.
diff -ur dnspython-1.5.0/dns/resolver.py
dnspython-1.5.0-vistafix/dns/resolver.py
--- dnspython-1.5.0/dns/resolver.py 2006-12-10 15:41:22.000000000 -0500
+++ dnspython-1.5.0-vistafix/dns/resolver.py 2007-02-01 17:48:38.060200000
-0500
@@ -452,17 +452,13 @@
try:
guid = _winreg.EnumKey(interfaces, i)
i += 1
+
+ if not self._win32_is_nic_enabled(lm, guid):
+ continue
+
key = _winreg.OpenKey(interfaces, guid)
try:
- # enabled interfaces seem to have a non-empty
- # NTEContextList
- try:
- (nte, ttype) = _winreg.QueryValueEx(key,
- 'NTEContextList')
- except WindowsError:
- nte = None
- if nte:
- self._config_win32_fromkey(key)
+ self._config_win32_fromkey(key)
finally:
key.Close()
except EnvironmentError:
@@ -472,6 +468,49 @@
finally:
lm.Close()
+ def _win32_is_nic_enabled(self, lm, guid):
+ # Look in the Windows Registry to determine whether the network
+ # interface corresponding to the given guid is enabled.
+
+ try:
+ # This hard-coded location seems to be consistent, at least
+ # from Windows 2000 through Vista.
+ connection_key = _winreg.OpenKey(
+ lm,
+ r'SYSTEM\CurrentControlSet\Control\Network'
+ r'\{4D36E972-E325-11CE-BFC1-08002BE10318}'
+ r'\%s\Connection' % guid)
+
+ try:
+ # The PnpInstanceID points to a key inside Enum
+ (pnp_id, ttype) = _winreg.QueryValueEx(
+ connection_key, 'PnpInstanceID')
+
+ if ttype != _winreg.REG_SZ:
+ raise ValueError
+
+ device_key = _winreg.OpenKey(
+ lm, r'SYSTEM\CurrentControlSet\Enum\%s' % pnp_id)
+
+ try:
+ # Get ConfigFlags for this device
+ (flags, ttype) = _winreg.QueryValueEx(
+ device_key, 'ConfigFlags')
+
+ if ttype != _winreg.REG_DWORD:
+ raise ValueError
+
+ # Based on experimentation, bit 0x1 indicates that the
+ # device is disabled.
+ return not (flags & 0x1)
+
+ finally:
+ device_key.Close()
+ finally:
+ connection_key.Close()
+ except (EnvironmentError, ValueError):
+ return False
+
def _compute_timeout(self, start):
now = time.time()
if now < start:
_______________________________________________
dnspython-dev mailing list
[email protected]
http://woof.play-bow.org/mailman/listinfo/dnspython-dev