diff --git a/inc/Data/Driver/Dns/HostDnsDriver.php b/inc/Data/Driver/Dns/HostDnsDriver.php new file mode 100644 index 00000000..b860256a --- /dev/null +++ b/inc/Data/Driver/Dns/HostDnsDriver.php @@ -0,0 +1,43 @@ +timeout = $timeout; + } + + public function nameToIPs(string $name): ?array { + $ret = shell_exec_error("host -W {$this->timeout} {$name}"); + if ($ret === false) { + return null; + } + + $ipv4 = self::matchOrEmpty('/has address ([^\s]+)/', $ret); + $ipv6 = self::matchOrEmpty('/has IPv6 address ([^\s]+)/', $ret); + return \array_merge($ipv4, $ipv6); + } + + public function IPToNames(string $ip): ?array { + $ret = shell_exec_error("host -W {$this->timeout} {$ip}"); + if ($ret === false) { + return null; + } + + $names = self::matchOrEmpty('/domain name pointer ([^\s]+)\./', $ret); + return \array_map(fn($n) => \strtolower(\rtrim($n, '.')), $names); + } +}