amphp / dns

Async DNS resolution for PHP based on Amp.
https://amphp.org/dns
MIT License
157 stars 32 forks source link

"Could not find a nameserver in the Windows Registry" out-of-the-box on Windows #49

Closed Daniel15 closed 7 years ago

Daniel15 commented 7 years ago

I'm hitting this exception when trying to use this library:

Fatal error:  Uncaught exception 'Amp\Dns\ResolutionException' with message 'Could not find a nameserver in the Windows Registry.' in C:\src\dnstools.ws\vendor\amphp\dns\lib\DefaultResolver.php:383
Stack trace:
#0 [internal function]: Amp\Dns\DefaultResolver::loadResolvConf()
#1 C:\src\dnstools.ws\vendor\amphp\amp\lib\functions.php(874): Generator->throw(Object(Amp\WindowsRegistry\KeyNotFoundException))
#2 [internal function]: Amp\__coroutineSend(Object(Amp\WindowsRegistry\KeyNotFoundException), NULL, Object(Amp\CoroutineState))
#3 C:\src\dnstools.ws\vendor\amphp\amp\lib\Placeholder.php(91): call_user_func('Amp\\__coroutine...', Object(Amp\WindowsRegistry\KeyNotFoundException), NULL, Object(Amp\CoroutineState))
#4 C:\src\dnstools.ws\vendor\amphp\amp\lib\PrivatePromisor.php(20): Amp\PrivatePlaceholder->resolve(Object(Amp\WindowsRegistry\KeyNotFoundException), NULL)
#5 [internal function]: Amp\PrivatePlaceholder->Amp\{closure}(Object(Amp\WindowsRegistry\KeyNotFoundException), NULL)
#6 C:\src\dnstools.ws\vendor\amphp\amp\lib\ in C:\src\dnstools.ws\vendor\amphp\dns\lib\DefaultResolver.php on line 383

Looking at https://github.com/amphp/dns/blob/8659b56263e5d74131782b9cb872a1ff64d6af4c/lib/DefaultResolver.php#L353-L372, it looks like the code looks for these keys:

However, on my computer, the DNS server is at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{55de6892-f5b0-4632-aeb8-d34874155c77}\DhcpNameServer.

Instead of just looking at Interfaces\{guid}\NameServer, I think it should also look for Interfaces\{guid}\DchpNameServer.

I'm on Windows 10, using DHCP.

kelunik commented 7 years ago

Thanks for the report, I added support for that.

kelunik commented 7 years ago

It's included in https://github.com/amphp/dns/releases/tag/v0.8.14.