MDL-66732 core: improve detection of non-public sites.

This commit is contained in:
Paul Holden
2020-04-15 21:54:29 +01:00
parent df0e58adb1
commit ab106ad70f
2 changed files with 20 additions and 0 deletions
+18
View File
@@ -245,4 +245,22 @@ final class ip_utils {
return false;
}
/**
* Return IP address for given hostname, or null on failure
*
* @param string $hostname
* @return string|null
*/
public static function get_ip_address(string $hostname): ?string {
if (self::is_domain_name($hostname)) {
$address = gethostbyname($hostname);
// If address is different from hostname, we have success.
if (strcasecmp($address, $hostname) !== 0) {
return $address;
}
}
return null;
}
}