-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows-specific read_registry / _win32_is_nic_enabled error on AWS EC2 #650
Comments
We are definitely open to PRs to do things better on Windows. Re the attached zip file, I'd prefer something written from scratch that we could ship under the dnspython ISC license rather than adapting code under another license. |
Great! I'd like to participate. I've read LICENSE but the two sections quickly got me confused. If I write code from scratch, submit the PR, and it gets accepted, who owns the copyright? There are three different copyright assertions:
[edit] @rthalley could you please provide more clarity about "the dnspython ISC license" you referred to? I would like to comply and get this code fixed. Thanks! |
Your code would not be donated to Google. The LICENSE file text about Nominum and Google is just mentioning the other copyrights, basically MIT-style, of some code contributed by Nominum and Google before we started using the ISC license. See https://opensource.org/licenses/ISC for info on the ISC license. If you don't put a copyright and license on the file, I will apply the "Dnspython Contributors" text to it. You can put a copyright and ISC license with your name on the code you are contributing if you'd like. I'd then add the "Dnspython Contributors" copyright to it to cover any subsequent changes we made to it, but your copyright and license would remain in the file. |
See the #722 PR for my plans in this area. Also note my theory about why the ConfigFlags test failed. If this is something you can check in your AWS environment, I'd be interested to know. |
This PR has been merged. |
Note you need to "pip install WMI" to get the more accurate way |
I'll try to test it out this weekend. |
@rthalley once I ensured This is my test script
Should I have expected |
"pip install wmi" is the way to install what dnspython needs. Installing dnspython with pip does not currently install WMI as we're still testing if it works well enough to be the default. If you are feeling adventurous, I am curious what happens if you edit win32util.py and make the following changes: On line 7, set _prefer_wmi = False On line 188, change "flags & 0x1" to "flags & 0x03". Then rerun your test and see if it did the right thing. I think the WMI way is the best way, but I'm curious about which part of the ConfigFlags technique was wrong :). No worries if you do not wish to do this. |
Oh, and thanks for doing the test! It's super helpful! |
Unfortunately, Debugging the code from
and then, in
You can see that
I don't know enough about the AWS EC2 environment to understand which of these interfaces is the one we ought to be looking at. However, when I run
Likewise, when running this in Powershell
Leading me to think that the first interface (in the |
Regarding the The problem is caused by the EC2 coming "pre-equipped" with a version of Python (or some of its DLLs) in a folder that is in the Path. This System path setting apparently preempts the technique I think
Copying |
Thanks for the experiment. It seems that the issue is that the old code is just finding everything instead of finding the same DNS settings that windows picks. |
Agreed. I just finished a much simpler approach to solving this problem (obviating the registry and WMI). I'd be happy to donate it to the It uses (I also did a "clean room" version of calling Please give this file a look and tell me what you think? |
We need the domain and search list too. It looks like the DnsQueryConfig technique can get the domain, but from the documentation it looks like DnsConfigSearchList is not implemented. I remember looking at this call. I rejected GetNetworkParams as it looked very complicated to call. The WMI method, while probably absurdly complicated internally, was really easy to call and gave me high-level output. If I've missed something and we can get the search list, let me know. |
The other file in my prototype repo uses Unfortunately, I'm a DNS dunce, and don't know what the search list is! Do you have any pointer(s) so I can read up on that? [another edit] So, I think I should focus on getting the import dns.resolver
dns_resolver = dns.resolver.Resolver()
print(f"{dns_resolver.domain=}")
print(f"{dns_resolver.nameservers=}")
print(f"{dns_resolver.search=}") |
Yes, the sample code shows the three things we're trying to get. And yes, the search list I mentioned is what Windows calls the DnsSuffixSearchOrder. I don't see it in GetNetworkParams either. Historically, the search list was used to save typing. If you typed in a name (typically one without dots though I guess XP might have done the wrong thing), then the local DNS resolver would try to lookup names with the various suffixes on the search list, and take the first one that existed. E.g. if you said "ping the_server" and the search list was a.example.com, b.example.com, then it would lookup the_server.a.example.com, and if it didn't exist, would look up the_server.b.example.com. The actual rules are a bit more complicated, see _get_qnames_to_try() in resolver.py if curious. See e.g. DnsSuffixSearchOrder It's really better NOT to use the search list, and dnspython doesn't use it by default now with its resolve() method, but some use cases need it so we support it. Also the existing registry scraping code supports it, so I wouldn't want to give it up. Getting pywin32 fixed seems like a good plan. |
I opened an issue mhammond/pywin32#1803. They might view it as an AWS issue (which would be fair), but it shows potential pitfalls for consumers of |
Specifically, the experimentally derived test for a
1
on internal Registry valueConfigFlags
doesn't work. The code erroneously thinks that a disabled network adapter is enabled. Based on this error, it uses the wrong DNS server address.dnspython/dns/resolver.py
Line 938 in 585add9
Microsoft documents that
ConfigFlags
is for internal use only.Additionally, Microsoft has a supported API GetNetworkParams, that has been available since Windows 2000, to get the DNS nameservers.
I'd like to suggest that we consider using
GetNetworkParams
instead of the Windows Registry code to produce the list of nameservers.I've attached a zipped standalone Python script that uses
GetNetworkParams
to produce the list of DNS nameservers on a Windows machine. I've tested it on a Windows 10 desktop and an AWS EC2 running Windows Server 2019 Datacenter Version 1809. It relies on the built-inctypes
package to accessGetNetworkParams
. The attached code isn't a pull request, as I wanted to gauge the project's level of interest in fixing this bug first.win_dns_nameservers.zip
The text was updated successfully, but these errors were encountered: