amphp / dns

Async DNS resolution for PHP based on Amp.

Home Page:https://amphp.org/dns

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Daniel15 opened this issue · comments

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

dns/lib/DefaultResolver.php

Lines 353 to 372 in 8659b56

$keys = [
"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\NameServer",
"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\DhcpNameServer",
];
$reader = new WindowsRegistry;
$nameserver = "";
while ($nameserver === "" && ($key = array_shift($keys))) {
try {
$nameserver = (yield $reader->read($key));
} catch (KeyNotFoundException $e) { }
}
if ($nameserver === "") {
$subKeys = (yield $reader->listKeys("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces"));
while ($nameserver === "" && ($key = array_shift($subKeys))) {
try {
$nameserver = (yield $reader->read("{$key}\\NameServer"));
, it looks like the code looks for these keys:

  • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NameServer
  • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DhcpNameServer
  • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{guid}\NameServer

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.

Thanks for the report, I added support for that.