php-whois/examples/check.php
2026-11-28 15:28:05 +02:00

35 lines
1.4 KiB
PHP

<?php
// Usage: php examples/check.php example.co.mz [more domains...]
// Works without a key. Set INTERWEB_API_KEY for the higher limit of your account.
require __DIR__ . '/../autoload.php'; // with Composer: require 'vendor/autoload.php';
use InterwebMz\Whois\Client;
use InterwebMz\Whois\Exception\RateLimitException;
use InterwebMz\Whois\Exception\WhoisException;
$whois = new Client();
foreach (array_slice($argv, 1) ?: ['example.co.mz'] 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";
}
}