mirror of
https://github.com/danog/dns.git
synced 2024-11-26 12:04:40 +01:00
Move localhost fallback generation to Config, use cloudflare DNS as DNS fallback
This commit is contained in:
parent
2cc9e78a96
commit
861cc857b1
@ -115,17 +115,6 @@ final class BasicResolver implements Resolver {
|
||||
|
||||
$name = normalizeDnsName($name);
|
||||
|
||||
if (in_array($name, ['localhost', 'localhost.'])) {
|
||||
switch ($typeRestriction) {
|
||||
case Record::A:
|
||||
return [new Record('127.0.0.1', Record::A, null)];
|
||||
case Record::AAAA:
|
||||
return [new Record('::1', Record::AAAA, null)];
|
||||
default:
|
||||
return [new Record('127.0.0.1', Record::A, null), new Record('::1', Record::AAAA, null)];
|
||||
}
|
||||
}
|
||||
|
||||
if ($records = $this->queryHosts($name, $typeRestriction)) {
|
||||
return $records;
|
||||
}
|
||||
@ -340,7 +329,7 @@ final class BasicResolver implements Resolver {
|
||||
try {
|
||||
$this->config = yield $this->configLoader->loadConfig();
|
||||
} catch (\Exception $e) {
|
||||
$this->config = new Config(['8.8.8.8:53', '8.8.4.4:53', '[2001:4860:4860::8888]:53', '[2001:4860:4860::8844]:53']);
|
||||
$this->config = new Config(['1.1.1.1:53', '1.0.0.1:53', '[2606:4700:4700::1111]:53', '[2606:4700:4700::1001]:53']);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -25,6 +25,18 @@ final class Config {
|
||||
throw new ConfigException("Invalid attempt count ({$attempts}), must be 1 or greater");
|
||||
}
|
||||
|
||||
// Windows does not include localhost in its host file. Fetch it from the system instead
|
||||
if (!isset($knownHosts[Record::A]["localhost"]) && !isset($knownHosts[Record::AAAA]["localhost"])) {
|
||||
// PHP currently provides no way to **resolve** IPv6 hostnames (not even with fallback)
|
||||
$local = \gethostbyname("localhost");
|
||||
if ($local !== "localhost") {
|
||||
$knownHosts[Record::A]["localhost"] = $local;
|
||||
} else {
|
||||
$knownHosts[Record::A]["localhost"] = '127.0.0.1';
|
||||
}
|
||||
$knownHosts[Record::AAAA]["localhost"] = "::1";
|
||||
}
|
||||
|
||||
$this->nameservers = $nameservers;
|
||||
$this->knownHosts = $knownHosts;
|
||||
$this->timeout = $timeout;
|
||||
|
@ -58,17 +58,6 @@ class HostLoader {
|
||||
}
|
||||
}
|
||||
|
||||
// Windows does not include localhost in its host file. Fetch it from the system instead
|
||||
if (!isset($data[Record::A]["localhost"]) && !isset($data[Record::AAAA]["localhost"])) {
|
||||
// PHP currently provides no way to **resolve** IPv6 hostnames (not even with fallback)
|
||||
$local = \gethostbyname("localhost");
|
||||
if ($local !== "localhost") {
|
||||
$data[Record::A]["localhost"] = $local;
|
||||
} else {
|
||||
$data[Record::AAAA]["localhost"] = "::1";
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user