2017 © Pedro Pelรกez
 

library php-whois

PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 5.4+ and 7+ compatible

image

io-developer/php-whois

PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 5.4+ and 7+ compatible

  • Saturday, July 28, 2018
  • by io-developer
  • Repository
  • 9 Watchers
  • 38 Stars
  • 1,110 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 14 Forks
  • 0 Open issues
  • 19 Versions
  • 142 % Grown

The README.md

PHP WHOIS

PHP version Packagist, (*1)

PHP WHOIS client implementation. Sends the queries directly to the WHOIS services., (*2)

Use case

  • Raw and parsed domain lookup
  • Raw and parsed ASN routes lookup
  • Direct queries to TLD/ASN hosts
  • Extending and customizing the default hosts, parsers, etc.
  • Proxying via CurlLoader

Installation

System requirements:
  • PHP >= 7.2__ (old versions supports __5.4+)
  • php-curl
  • php-mbstring
  • Open port 43 in firewall

Optional: * php-intl * php-memcached + Memcached server, (*3)

Project requirements:
  • PSR-4 autoloader
Composer:
composer require io-developer/php-whois

or composer.json:, (*4)

"require": {
    "io-developer/php-whois": "^4.0"
}

Usage

Domain lookup

How to get summary about domain:
<?php

use Iodev\Whois\Factory;

// Creating default configured client
$whois = Factory::get()->createWhois();

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

// Supports Unicode (converts to punycode)
if ($whois->isDomainAvailable("ะฟะพั‡ั‚ะฐ.ั€ั„")) {
    print "Bingo! Domain is available! :)";
}

// Getting raw-text lookup
$response = $whois->lookupDomain("google.com");
print $response->text;

// Getting parsed domain info
$info = $whois->loadDomainInfo("google.com");
print_r([
    'Domain created' => date("Y-m-d", $info->creationDate),
    'Domain expires' => date("Y-m-d", $info->expirationDate),
    'Domain owner' => $info->owner,
]);

Exceptions on domain lookup:
<?php

use Iodev\Whois\Factory;
use Iodev\Whois\Exceptions\ConnectionException;
use Iodev\Whois\Exceptions\ServerMismatchException;
use Iodev\Whois\Exceptions\WhoisException;

try {
    $whois = Factory::get()->createWhois();
    $info = $whois->loadDomainInfo("google.com");
    if (!$info) {
        print "Null if domain available";
        exit;
    }
    print $info->domainName . " expires at: " . date("d.m.Y H:i:s", $info->expirationDate);
} catch (ConnectionException $e) {
    print "Disconnect or connection timeout";
} catch (ServerMismatchException $e) {
    print "TLD server (.com for google.com) not found in current server hosts";
} catch (WhoisException $e) {
    print "Whois server responded with error '{$e->getMessage()}'";
}
Proxy with SOCKS5:
<?php

use Iodev\Whois\Loaders\CurlLoader;
use Iodev\Whois\Factory;

$loader = new CurlLoader();
$loader->replaceOptions([
    CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,
    CURLOPT_PROXY => "127.0.0.1:1080",
    //CURLOPT_PROXYUSERPWD => "user:pass",
]);
$whois = Factory::get()->createWhois($loader);

var_dump([
    'ya.ru' => $whois->loadDomainInfo('ya.ru'),
    'google.de' => $whois->loadDomainInfo('google.de'),
]);
TLD hosts customization:
<?php

use Iodev\Whois\Factory;
use Iodev\Whois\Modules\Tld\TldServer;

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

// Define custom whois host
$customServer = new TldServer(".custom", "whois.nic.custom", false, Factory::get()->createTldParser());

// Or define the same via assoc way
$customServer = TldServer::fromData([
    "zone" => ".custom",
    "host" => "whois.nic.custom",
]);

// Add custom server to existing whois instance
$whois->getTldModule()->addServers([$customServer]);

// Now it can be utilized
$info = $whois->loadDomainInfo("google.custom");

var_dump($info);
TLD default/fallback servers:
<?php

use Iodev\Whois\Factory;
use Iodev\Whois\Modules\Tld\TldServer;

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

// Add default servers
$matchedServers = $whois->getTldModule()
    ->addServers(TldServer::fromDataList([
        ['zone' => '.*.net', 'host' => 'localhost'],
        ['zone' => '.uk.*', 'host' => 'localhost'],
        ['zone' => '.*', 'host' => 'localhost'],
    ]))
    ->matchServers('some.uk.net');

foreach ($matchedServers as $s) {
    echo "{$s->getZone()}  {$s->getHost()}\n";
}

// Matched servers + custom defaults:
//
// .uk.net  whois.centralnic.com
// .uk.net  whois.centralnic.net
// .uk.*  localhost
// .*.net  localhost
// .net  whois.crsnic.net
// .net  whois.verisign-grs.com
// .*  localhost

ASN lookup

How to get summary using ASN number:
<?php

use Iodev\Whois\Factory;

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

// Getting raw-text lookup
$response = $whois->lookupAsn("AS32934");
print $response->text;

// Getting parsed ASN info
$info = $whois->loadAsnInfo("AS32934");
foreach ($info->routes as $route) {
    print_r([
        'route IPv4' => $route->route,
        'route IPv6' => $route->route6,
        'description' => $route->descr,
    ]);   
}

Response caching

Some TLD hosts are very limited for frequent requests. Use cache if in your case requests are repeating., (*5)

<?php

use Iodev\Whois\Factory;
use Iodev\Whois\Loaders\SocketLoader;
use Iodev\Whois\Loaders\MemcachedLoader;

$m = new Memcached();
$m->addServer('127.0.0.1', 11211);
$loader = new MemcachedLoader(new SocketLoader(), $m);

$whois = Factory::get()->createWhois($loader);
// do something...

Develompment

Supported php versions are configured in docker-compose.yml, (*6)

Common use cases: 1. Set up & run all tests: docker compose up --build 2. Run tests under specific php version: docker compose up php-8.2_intl --build 3. Run scripts: docker compose run php-8.2_intl bin/php-whois info google.com, (*7)

Also see TESTS.md, (*8)

Contributing

The project is open for pull requests, issues and feedback. Please read the CODE_OF_CONDUCT.md, (*9)

The Versions

28/07 2018

dev-dev

dev-dev https://github.com/io-developer/php-whois

PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 5.4+ and 7+ compatible

  Sources   Download

MIT

The Requires

  • ext-intl *
  • php >=5.4
  • ext-mbstring *

 

The Development Requires

parser domain php query client information registrar expiration routes unicode availability asn whois tld lookup info expiry idna pure punycode punnycode registrant ั†ั€ั‰ัˆั‹

28/07 2018

dev-master

9999999-dev https://github.com/io-developer/php-whois

PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 5.4+ and 7+ compatible

  Sources   Download

MIT

The Requires

  • ext-intl *
  • php >=5.4
  • ext-mbstring *

 

The Development Requires

parser domain php query client information registrar expiration routes unicode availability asn whois tld lookup info expiry idna pure punnycode registrant ั†ั€ั‰ัˆั‹

17/07 2018

3.1.1

3.1.1.0 https://github.com/io-developer/php-whois

PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 5.4+ and 7+ compatible

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-intl *
  • ext-mbstring *

 

The Development Requires

parser domain php query routes asn whois tld lookup info ั†ั€ั‰ัˆั‹

14/07 2018

3.1.0

3.1.0.0 https://github.com/io-developer/php-whois

PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 5.4+ and 7+ compatible

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-intl *
  • ext-mbstring *

 

The Development Requires

parser domain php query routes asn whois tld lookup info ั†ั€ั‰ัˆั‹

07/07 2018

3.0.5

3.0.5.0 https://github.com/io-developer/php-whois

PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 5.4+ and 7+ compatible

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-intl *
  • ext-mbstring *

 

The Development Requires

parser domain php query routes asn whois tld lookup info ั†ั€ั‰ัˆั‹

04/07 2018

3.0.4

3.0.4.0 https://github.com/io-developer/php-whois

PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 5.4+ and 7+ compatible

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-intl *
  • ext-mbstring *

 

The Development Requires

parser domain php query routes asn whois tld lookup info ั†ั€ั‰ัˆั‹

25/06 2018

3.0.3

3.0.3.0 https://github.com/io-developer/php-whois

PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 5.4+ and 7+ compatible

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-intl *
  • ext-mbstring *

 

The Development Requires

parser domain php query routes asn whois tld lookup info ั†ั€ั‰ัˆั‹

07/06 2018

3.0.2

3.0.2.0 https://github.com/io-developer/php-whois

PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 5.4+ and 7+ compatible

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-intl *
  • ext-mbstring *

 

The Development Requires

parser domain php query routes asn whois tld lookup info ั†ั€ั‰ัˆั‹

19/05 2018

3.0.0

3.0.0.0 https://github.com/io-developer/php-whois

PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 5.4+ and 7+ compatible

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-intl *
  • ext-mbstring *

 

The Development Requires

parser domain php query routes asn whois tld lookup info ั†ั€ั‰ัˆั‹

26/11 2017

2.3.0

2.3.0.0 https://github.com/io-developer/php-whois

PHP WHOIS client implementation. Provides raw-text and parsed answers. Allows easy check domain availability or expiration date. Sends WHOIS queries to real service via port 43

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-intl *

 

The Development Requires

parser domain php client information registrar expiration unicode availability whois lookup expiry idna pure punnycode registrant

23/11 2017

2.2.0

2.2.0.0 https://github.com/io-developer/php-whois

Pure PHP WHOIS client provides raw and parsed WHOIS domain information. Easy way to check domain availability or expiration date. Implements requests to real WHOIS service via port 43

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-intl *

 

The Development Requires

parser domain php client information registrar expiration unicode availability whois lookup idna pure punnycode

10/11 2017

2.1.0

2.1.0.0 https://github.com/io-developer/php-whois

Pure PHP WHOIS client provides raw and parsed WHOIS domain information. Easy way to check domain availability or expiration date. Implements requests to real WHOIS service via port 43

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-intl *

 

The Development Requires

parser domain php client information registrar expiration unicode availability whois lookup idna pure punnycode

07/11 2017

2.0.2

2.0.2.0 https://github.com/io-developer/php-whois

Provides parsed WHOIS domain information. Easy way to check domain availability or expiration date. Implements requests to real WHOIS service via port 43

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-intl *

 

The Development Requires

parser domain client information registrar expiration availability whois lookup idna

07/11 2017

2.0.1

2.0.1.0 https://github.com/io-developer/php-whois

Provides parsed WHOIS domain information. Easy way to check domain availability or expiration date. Implements requests to real WHOIS service via port 43

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-intl *

 

The Development Requires

parser domain client information registrar expiration availability whois lookup idna

06/11 2017

2.0.0

2.0.0.0 https://github.com/io-developer/php-whois

Provides parsed WHOIS domain information. Easy way to check domain availability or expiration date. Implements requests to real WHOIS service via port 43

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-intl *

 

The Development Requires

parser domain client information registrar expiration availability whois lookup idna

14/10 2017

1.2.2

1.2.2.0 https://github.com/io-developer/php-whois

Provides parsed WHOIS domain information. Easy way to check domain availability or expiration date. Implements requests to real WHOIS service via port 43

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-intl *

 

The Development Requires

parser domain client information registrar expiration availability whois lookup idna

12/10 2017

1.2.1

1.2.1.0 https://github.com/io-developer/php-whois

Provides parsed WHOIS domain information. Easy way to check domain availability or expiration date. Implements requests to real WHOIS service via port 43

  Sources   Download

MIT

The Requires

  • php >=5.6
  • ext-intl *

 

domain information registrar expiration availability whois idna

12/10 2017

1.2.0

1.2.0.0 https://github.com/io-developer/php-whois

Library implements requests to real WHOIS service (via port 43) and provides parsed responses

  Sources   Download

MIT

The Requires

  • php >=5.6
  • ext-intl *

 

domain client registrar expiration whois site info host idna

08/10 2017

1.1.0

1.1.0.0 https://github.com/io-developer/php-whois

Library implements requests to real WHOIS service (via port 43) and provides parsed responses

  Sources   Download

MIT

The Requires

  • php >=5.6
  • ext-intl *