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
440 stars 118 forks source link

Disconnect or connection timeout for any domain #117

Closed stremshs closed 3 years ago

stremshs commented 4 years ago

PHP-Whois version: 4.0.0 I guess (master at this date)

PHP version: 7.2.30

Description
Executing the script always returns "Disconnect or connection timeout". No matter TLD I'm executing (com/eu/fr...)

How to reproduce

<?php
require __DIR__ . '/vendor/autoload.php';

use Iodev\Whois\Factory;
use Iodev\Whois\Exceptions\ConnectionException;
use Iodev\Whois\Exceptions\ServerMismatchException;
use Iodev\Whois\Exceptions\WhoisException;
use Iodev\Whois\Modules\Tld\TldServer;

$domain = $_GET['domain'];

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

    // Checking availability
    if ($whois->isDomainAvailable($domain)) {
        print "Bingo! $domain is available! :)";
    }

    // Getting raw-text lookup
    if ($response = $whois->lookupDomain($domain)) {
        print $response->text;
    }

    // Getting parsed domain info
    $info = $whois->loadDomainInfo($domain);
    if (!$info) {
        print "Null if domain available";
        exit;
    }
    print $info->domainName . " expires at: " . date("d.m.Y H:i:s", $info->expirationDate);
    print_r([
        'Domain created' => date("Y-m-d", $info->creationDate),
        'Domain expires' => date("Y-m-d", $info->expirationDate),
        'Domain owner' => $info->owner,
    ]);

} catch (ConnectionException $e) {
    print "Disconnect or connection timeout";
} catch (ServerMismatchException $e) {
    print "TLD server not found in current server hosts";
} catch (WhoisException $e) {
    print "Whois server responded with error '{$e->getMessage()}'";
}

Possible Solution
Maybe the server I'm using (shared instance on o2switch.net) blocks the outgoing requests. Can it be ? What kind of request does the script send ? Through which port ? This to open it ;-)

Additional context
I've tried bessone version : no luck.

Thank you so much !

bessone commented 4 years ago

Hello, my version is just a fork i use for some PR, if this one doesn't work, mine won't work for sure.

Have you tried connecting to ssh on the server and doing from there a whois from linux shell?

io-developer commented 3 years ago

Yes, it's definitely possible your hosting provider blocks port 43 for requests/responses.