35 lines
1.3 KiB
PHP
35 lines
1.3 KiB
PHP
<?php
|
|
// Usage: php examples/check.php example.com [more domains...]
|
|
// Works without a key. Set MOZOUT_API_KEY for the higher limit of your account.
|
|
|
|
require __DIR__ . '/../autoload.php'; // with Composer: require 'vendor/autoload.php';
|
|
|
|
use MozOut\Whois\Client;
|
|
use MozOut\Whois\Exception\RateLimitException;
|
|
use MozOut\Whois\Exception\WhoisException;
|
|
|
|
$whois = new Client();
|
|
|
|
foreach (array_slice($argv, 1) ?: ['example.com'] as $domain) {
|
|
try {
|
|
$r = $whois->lookup($domain);
|
|
} catch (RateLimitException $e) {
|
|
exit("Too many lookups. Try again in " . ($e->getRetryAfter() ?? 60) . " seconds.\n");
|
|
} catch (WhoisException $e) {
|
|
echo "$domain: " . $e->getMessage() . "\n";
|
|
continue;
|
|
}
|
|
|
|
if ($r->isAvailable()) {
|
|
printf("%s is free: %.2f %s per year. Register: %s\n", $r->domain(), $r->registerPrice(), $r->currency(), $r->registerUrl());
|
|
} elseif ($r->isRegistered()) {
|
|
$expires = $r->expiresAt();
|
|
printf("%s is registered%s. Nameservers: %s\n", $r->domain(),
|
|
$expires ? ', it expires on ' . $expires->format('d/m/Y') : '', implode(', ', $r->nameservers()) ?: '-');
|
|
foreach ($r->alternatives() as $alt) {
|
|
echo " Free alternative: {$alt['domain']} ({$alt['price']})\n";
|
|
}
|
|
} else {
|
|
echo $r->domain() . ': ' . $r->status() . "\n";
|
|
}
|
|
}
|