From 72d68fa1aba4e27ff87796fc2b9bbc6ee333fd42 Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 21 May 2024 21:07:11 +1000 Subject: [PATCH] Update SocketClient to support raw IP addresses --- app/Classes/Sock/SocketClient.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/Classes/Sock/SocketClient.php b/app/Classes/Sock/SocketClient.php index a8a7aae..e1b7cc4 100644 --- a/app/Classes/Sock/SocketClient.php +++ b/app/Classes/Sock/SocketClient.php @@ -201,10 +201,16 @@ final class SocketClient { $sort = collect(['AAAA','A']); - // We only look at AAAA/A records - $resolved = collect(dns_get_record($address,DNS_AAAA|DNS_A)) - ->filter(function($item) use ($sort) { return $sort->search(Arr::get($item,'type')) !== FALSE; }) - ->sort(function($item) use ($sort) { return $sort->search(Arr::get($item,'type')); }); + if (filter_var($address,FILTER_VALIDATE_IP)) + $resolved = collect([[ + (($x=filter_var($address,FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) ? 'ipv6' : 'ip')=>$address, + 'type'=>$x ? 'AAAA' : 'A' + ]]); + else + // We only look at AAAA/A records + $resolved = collect(dns_get_record($address,DNS_AAAA|DNS_A)) + ->filter(function($item) use ($sort) { return $sort->search(Arr::get($item,'type')) !== FALSE; }) + ->sort(function($item) use ($sort) { return $sort->search(Arr::get($item,'type')); }); if (! $resolved->count()) throw new SocketException(SocketException::CANT_CONNECT,sprintf('%s doesnt resolved to an IPv4/IPv6 address',$address));