Per ogni estensione di dominio (.it, .com, .org etc.) il whois a cui fai fare la ricerca (whois.nic.it etc. ) processa una frase tipica nel caso che il dominio è libero (es. No entries found, FREE etc.).
Pertanto , quando l'avevo fatto io cercavo quella frase, e se veniva matchata indicavo dominio Libero, viceversa Occupato.
Lo script è un po' datato però rende l'idea: (è solo un estratto)
Eccolo:
<form method="POST" action= "">
<tr><td width="463">
<span class="text">Verifica se il dominio che vuoi registrare è libero</span>
<? if ($dominio!=""){ ?>
<span class="text">Dominio selezionato:<? echo $dominio.".".$ext ?></span>
<? } ?>
<?php
$dominio = strtolower(trim($dominio));
if ($dominio !=""){
$dominio=$dominio.".".$ext;
/*
Il dominio di secondo livello sui cui desideriamo ricavare informazioni,
notare l'assenza di "WWW"
*/
//$dominio ='websiteeb.com' ;
switch($ext)
{
case "it":
$whois = "whois.nic.it";
$testo_match="No entries found";
break;
case "eu":
$whois = "whois.eu";
$testo_match="FREE";
break;
case "com":
$whois = "whois.crsnic.net";
$testo_match="No match for";
break;
case "net":
$whois = "whois.crsnic.net";
$testo_match="No match for";
break;
case "org":
$whois = "whois.publicinterestregistry.net";
$testo_match="NOT FOUND";
break;
case "cn":
$whois = "whois.cnnic.net.cn";
$testo_match="no matching record";
break;
case "cc":
$whois = "whois.nic.cc";
$testo_match="No match";
break;
case "co.uk":
$whois = "whois.nic.uk";
$testo_match="No match";
break;
case "org.uk":
$whois = "whois.nic.uk";
$testo_match="No match";
break;
case "ca":
$whois = "whois.cira.ca";
$testo_match="AVAIL";
break;
case "us":
$whois = "whois.nic.us";
$testo_match="Not found:";
break;
case "name":
$whois = "whois.nic.name";
$testo_match="No match";
break;
case "fr":
$whois = "whois.nic.fr";
$testo_match="No entries found";
break;
case "nl":
$whois = "whois.domain-registry.nl";
$testo_match="is free";
break;
case "tv":
$whois = "whois.www.tv";
$testo_match="Whois information is not available for domain";
break;
}
/*
l'host del servizio
*/
$info = '' ;
/*
La connessione
*/
$sk=fsockopen($whois, 43, $errno, $errstr, 30) or die('Connessione impossibile') ;
/*
Inviamo la request
*/
fputs ($sk, $dominio."\r\n") or die('Request impossibile') ;
/*
Leggiamo il response
*/
while (!feof($sk)) {
$info.= fgets ($sk, 2048);
}
/*
Output con le informazioni ricavate
*/
$libero=strpos($info,$testo_match);
if (!$libero){
echo "<span class=\"evidenzia\">Dominio già registrato!</span>";
}else{
echo "<span class=\"evidenzia\">Dominio Libero:</span>";
echo " <a href=\"ordina.php?dominio=$dominio\" class=titblu1>Ordina</a>";
}
?>
</td>
</tr>
<tr><td width="463">
<?
echo('<pre>'.$info.'</pre>') ;
?>
</td>
</tr>
<?
};
?>
</FORM>