mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-10-27 15:43:35 +03:00
Added \SnappyMail\DNS::IP($hostname) to get all related IP's
This commit is contained in:
parent
7bce091177
commit
8f645388fc
1 changed files with 21 additions and 10 deletions
|
|
@ -52,11 +52,8 @@ abstract class DNS
|
|||
public static function MX(string $domain) : array
|
||||
{
|
||||
$mxhosts = array();
|
||||
$values = \dns_get_record($domain, \DNS_MX);
|
||||
if ($values) {
|
||||
foreach ($values as $record) {
|
||||
$mxhosts[$record['pri']] = $record['target'];
|
||||
}
|
||||
foreach (\dns_get_record($host, \DNS_MX) ?: array() as $record) {
|
||||
$mxhosts[$record['pri']] = $record['target'];
|
||||
}
|
||||
if (!$mxhosts) {
|
||||
\getmxrr($domain, $mxhosts);
|
||||
|
|
@ -68,13 +65,27 @@ abstract class DNS
|
|||
public static function SRV(string $domain) : array
|
||||
{
|
||||
$result = array();
|
||||
$values = \dns_get_record($domain, \DNS_SRV);
|
||||
if ($values) {
|
||||
foreach ($values as $record) {
|
||||
$result[$record['pri']] = $record;
|
||||
}
|
||||
foreach (\dns_get_record($host, \DNS_SRV) ?: array() as $record) {
|
||||
$result[$record['pri']] = $record;
|
||||
}
|
||||
\ksort($result);
|
||||
return \array_values($result);
|
||||
}
|
||||
|
||||
public static function IP(string $domain): array
|
||||
{
|
||||
$ips = array();
|
||||
foreach (\dns_get_record($host, \DNS_A | (\defined('AF_INET6') ? \DNS_AAAA : 0)) ?: array() as $record) {
|
||||
if (!empty($record['ip'])) {
|
||||
$ips[] = $record['ip'];
|
||||
}
|
||||
if (!empty($record['ipv6'])) {
|
||||
$ips[] = $record['ipv6'];
|
||||
}
|
||||
}
|
||||
if (!$ips) {
|
||||
$ips = \gethostbynamel($host);
|
||||
}
|
||||
return $ips ?: array();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue