From a71fd35f6f1fe71f51ae7da03107646071ec9c5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Tue, 10 Jun 2025 10:37:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=81=A2=E5=A4=8D=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E7=89=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/utils/CheckUtils.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/utils/CheckUtils.php b/app/utils/CheckUtils.php index 192cb9e..e0ac27c 100644 --- a/app/utils/CheckUtils.php +++ b/app/utils/CheckUtils.php @@ -17,6 +17,18 @@ class CheckUtils if (!$urlarr) { return ['status' => false, 'errmsg' => 'Invalid URL', 'usetime' => 0]; } + if (str_starts_with($urlarr['host'], '[') && str_ends_with($urlarr['host'], ']')) { + $urlarr['host'] = substr($urlarr['host'], 1, -1); + } + if (!empty($ip) && !filter_var($urlarr['host'], FILTER_VALIDATE_IP)) { + if (!filter_var($ip, FILTER_VALIDATE_IP)) { + $ip = gethostbyname($ip); + } + if (!empty($ip) && filter_var($ip, FILTER_VALIDATE_IP)) { + $port = $urlarr['port'] ?? ($urlarr['scheme'] == 'https' ? 443 : 80); + $resolve = $urlarr['host'] . ':' . $port . ':' . $ip; + } + } $options = [ 'timeout' => $timeout, @@ -27,7 +39,13 @@ class CheckUtils ], 'http_errors' => false // 不抛出异常 ]; - + // 处理解析 + if (!empty($resolve)) { + $options['curl'] = [ + CURLOPT_DNS_USE_GLOBAL_CACHE => false, + CURLOPT_RESOLVE => [$resolve] + ]; + } // 处理代理 if ($proxy) { $proxy_server = config_get('proxy_server');