diff --git a/lib/Cleantalk/Common/Helper.php b/lib/Cleantalk/Common/Helper.php index 79e07925d..abf956bff 100644 --- a/lib/Cleantalk/Common/Helper.php +++ b/lib/Cleantalk/Common/Helper.php @@ -600,11 +600,33 @@ public static function ipResolve($ip) */ public static function dnsResolve($host, $out = false) { - // Check if the $url is set and it is an url - if ( ! $host || ! filter_var($host, FILTER_VALIDATE_URL)) { + // Validate/normalize host (accept hostname or IP; URLs and host:port are also supported) + if ( ! $host || ! is_string($host) ) { return $out; } + if ( strpos($host, '://') !== false ) { + $parsed_host = parse_url($host, PHP_URL_HOST); + if ( is_string($parsed_host) && $parsed_host !== '' ) { + $host = $parsed_host; + } + } + + if ( strpos($host, ':') !== false && ! filter_var($host, FILTER_VALIDATE_IP) ) { + $host = strstr($host, ':', true); + } + + $is_ip = filter_var($host, FILTER_VALIDATE_IP); + + if ( ! filter_var($host, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) + && ! $is_ip ) { + return $out; + } + + if ( $is_ip ) { + return $host; + } + // Get DNS records about URL if (function_exists('dns_get_record')) { $records = dns_get_record($host, DNS_A);