php-whois icon indicating copy to clipboard operation
php-whois copied to clipboard

set interface (xxx.xxx.xxx.xxx) with sockets

Open elnarvi opened this issue 2 years ago • 0 comments

Description
To avoid blocks in the whois server we use different IPs. With curl it is possible:

` $loader = new CurlLoader();

$loader->replaceOptions([ CURLOPT_INTERFACE => xxx.xxx.xxx.xxx, CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4 ]);

$whois = Factory::get()->createWhois($loader);

With socket it is faster but it is not possible...

Example

We have had to modify the code of the file:

vendor/io-developer/php-whois/src/Iodev/Whois/Loaders/SocketLoader.php

Changing:

$handle = @fsockopen($whoisHost, 43, $errno, $errstr, $this->timeout);

By:

` $socket_context = @stream_context_create(array("socket" => array("bindto" => "xxx.xxx.xxx.xxx:0")));

$handle = @stream_socket_client($whoisHost.":43", $errno, $errstr, $this->timeout, STREAM_CLIENT_CONNECT, $socket_context); `

elnarvi avatar Mar 29 '23 13:03 elnarvi