Skip to content

Use Windows API to get dns nameservers #1196

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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

blink1073
Copy link
Contributor

@blink1073 blink1073 commented May 7, 2025

Fixes #1191

As far as I can tell the only two ways of getting the search list are using COM or the registry, so I subclassed the registry getter.

Testing with a PR against my fork so I can run actions: blink1073#1

  • Get it to pass in GitHub Actions
  • Get it to pass in PyMongo CI
  • Establish how to configure the usage of this getter

@blink1073
Copy link
Contributor Author

@jaraco might you be able to verify that this fixes the issue for you as well? For PyMongo the relevant change was that we needed to ignore a loopback adapter.

@rthalley
Copy link
Owner

This patch is looking good so far. Ideally we want all three DnsInfo attributes. You've gotten the nameservers attribute. The DnsSuffix field is the domain attribute of DnsInfo (if not NULL or an empty string); if NULL or empty, the DnsInfo value should be None. The list at FirstDnsSuffix at the very bottom of the structure is what should go in the search field (or empty list if not there).

@blink1073
Copy link
Contributor Author

I did some more digging, and the FirstDnsSuffix is only set if the adapter is configured directly. I'm getting a null pointer for the value. If it is null, we need to fall back to using the registry. Here's what ipconfig looks like on our EC2 host:

$ ipconfig /all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : <snip>
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : us-east-1.ec2-utilities.amazonaws.com
                                       ec2.internal

Ethernet adapter Ethernet 4:

   Connection-specific DNS Suffix  . : ec2.internal
   Description . . . . . . . . . . . : Amazon Elastic Network Adapter #2
  <snip>
  DNS Servers . . . . . . . . . . . : 10.122.0.2

@blink1073
Copy link
Contributor Author

Actually, I can't find any indication that FirstDnsSuffix is what we want, but we know that the registry approach works, so I think the best compromise is to use the registry for the search list unconditionally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resolver uses DNS Servers from inactive interfaces on Windows, causing timeouts
2 participants