io-developer / php-whois

PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 8.0 compatible (5.4+ old versions)
MIT License
437 stars 117 forks source link

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

Open elnarvi opened 1 year ago

elnarvi commented 1 year ago

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); `