Skip to content

Instantly share code, notes, and snippets.

@ju5t
Created June 9, 2017 20:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ju5t/cd0db3563820dab7ad1d58a5b727f840 to your computer and use it in GitHub Desktop.
Save ju5t/cd0db3563820dab7ad1d58a5b727f840 to your computer and use it in GitHub Desktop.
<?php
/*
* A example of how to generate WHMCS-ready dist.whois.json files.
*/
$whoisServers = [];
$tlds = [];
$xml = simplexml_load_file('https://raw.githubusercontent.com/whois-server-list/whois-server-list/master/whois-server-list.xml');
foreach ($xml->domain as $id => $domain) {
// Make sure we start with a clean slate
$whois = new stdClass();
$tlds = [];
// Get a list of tld's
$tlds[] = '.' . $domain->attributes()['name']->__toString();
if (count($domain->domain) >= 1) {
foreach ($domain->domain as $secondary_domain_id => $secondary_tld) {
$tlds[] = '.' . $secondary_tld->attributes()['name']->__toString();
}
}
$tlds = implode(',', $tlds);
// Check if we know a whois server for this domain
if (isset($domain->whoisServer)) {
$whoisServer = $domain->whoisServer->attributes()['host']->__toString();
$availablePattern = $domain->whoisServer->availablePattern->__toString();
// Leave the matching up to WHMCS so let's remove \Q and \E
$availablePattern = preg_replace('/\\\[QE]{1}/', '', $availablePattern);
// Set
$whois->extensions = $tlds;
$whois->uri = "socket://${whoisServer}";
$whois->available = $availablePattern;
$whoisServers[] = $whois;
}
}
echo json_encode($whoisServers, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment