Skip to content

Instantly share code, notes, and snippets.

@oneluiz
Last active December 20, 2022 06:42
Show Gist options
  • Save oneluiz/280854f5120320c76aef5bcd2cf7d6f1 to your computer and use it in GitHub Desktop.
Save oneluiz/280854f5120320c76aef5bcd2cf7d6f1 to your computer and use it in GitHub Desktop.
PHP code to get WHOIS information of a domain
<?php
/**
* @author Luis Cortés
* [Whois description]
* @param string $whois [description]
* @param [type] $domain [description]
*/
function Whois($whois='', $domain){
$stringDataWhois="";
$Show = array();
$sock = fsockopen($whois, 43);
if(!$sock){
$Show[0]=false;
}else{
$Show[0]=true;
fwrite($sock, $domain."\r\n");
while(!feof($sock) ){
$stringDataWhois .= fgets($sock,128);
}
fclose($sock);
$Show[1]=$stringDataWhois;
}
return $Show;
}
$WhoisName = array(
'.com' =>array('whois.crsnic.net','No match for'),//.com
'.net' =>array('whois.crsnic.net','No match for'),// .net
'.bo' =>array('whois.nic.bo','whois.nic.bo solo acepta consultas con dominios .bo'),//.bo
'.mx' =>array('whois.nic.mx','No_Se_Encontro_El_Objeto'),//.mx
'.pe' =>array('whois.nic.pe','No Object Found'),//.pe
'.co' =>array('whois.nic.co','Not found'), //.co
'.es' =>array('whois.nic.es','Not found') //.cr
);
$DomainName = filter_var (empty($_POST['name']) ? false : $_POST['name'], FILTER_SANITIZE_STRING);
$DomainExtension = filter_var (empty($_POST['Ext']) ? false : $_POST['Ext'], FILTER_SANITIZE_STRING);
$increase = filter_var (empty($_POST['increase']) ? 0 : $_POST['increase'], FILTER_SANITIZE_NUMBER_INT);
if(strlen($DomainName)>0){
$stringParser="";
$DomainName = preg_replace(
array(
'/www./',
'/http:\//',
'/\//',
'/.com/',
'/.bo/',
'/.com.bo/',
'/edu.bo/',
'/.org.bo/',
'/.net/',
'/.mx/',
'/.pe/',
'/.co/'
),
'',
$DomainName
);
foreach ($WhoisName as $key => $value) {
if($key==$DomainExtension){
if (Whois($value[0],$DomainName.$DomainExtension)[0]==true){
$DataWhois= Whois($value[0],$DomainName.$DomainExtension)[1];
$Available = '<div class="alert alert-success alert-dismissible" style="width: 100%;" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span>Yes! Your domain <strong>'.$DomainName.$DomainExtension.'</strong> is available. Buy it before someone else does. </span><button class="btn btn-success ml-3" id="Enviar" type="button"><i class="im im-icon-Full-Cart"></i> Buy this domain</button></div>';
$NotAvailable = '<div class="alert alert-light alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span>Sorry, <strong>'.$DomainName.$DomainExtension.'</strong> is taken.</span><a class="btn btn-danger ml-3" role="button" data-toggle="collapse" href="#collapseExample'.$increase .'" aria-expanded="false" aria-controls="collapseExample'.$increase .'"> View domain information</a><div class="collapsing" id="collapseExample'.$increase .'"><div class="card mt-4 p-3"><pre>'.Whois($value[0],$DomainName.$DomainExtension)[1].'</pre></div></div></div>';
// We remove some characters
// of the Bolivian WHOIS server
if($key==".bo"){
$DataWhois=str_replace(array("\r\n", "\n", "\r"), '',$DataWhois);
if($DataWhois==$value[1]){
echo $Available;
}else{
echo $NotAvailable;
}
}else{
//searching...
if (preg_match("/".$value[1]."/i",$DataWhois)){
echo $Available ;
}else{
echo $NotAvailable;
}
}
}else{
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment