<?php
//select ext domain
$domain=$_POST['domain'];
$ext= $_POST['ext'];
$whoisServer="";
switch($ext){
case "com":
case "net":
case "edu":
$whoisServer="whois.internic.net";
break;
case "org":
$whoisServer="whois.publicinterestregistry.net";
break;
case "biz":
$whoisServer="whois.neulevel.biz";
break;
case "info":
$whoisServer="whois.afilias.info";
break;
case "ir":
case "id.ir":
case "co.ir":
case "net.ir":
$whoisServer="whois.nic.ir";
break;
default:
$whoisServer= "whois.networksolutions.com";
}
//This checks the name for invaild characters
function namecheck($domain)
{
if($domain==""){
echo"لطفا نام دامنه مورد نظر خود را وارد کنيد<br>\n";
cache = return false;
}
if(strlen($domain)< 3){
echo"The domain name <b>$domain</b> is too short";
return false;
}
if(strlen($domain)>57){
echo"The domain name <b>$domain </b> is too long";
return false;
}
if(@ereg("^-|-$",$domain)){
echo"Domains cannot begin or end with a hypen";
return false;
}
if(!ereg("([a-z]|[A-Z]|[0-9]|-){".strlen($domain)."}",$domain)){
echo"Domain names cannot contain special characters";
return false;
}
return true;
}
// connect to whois server
function dolookup($domain, $server){
$domain = strtolower($domain);
$server = strtolower($server);
if( $domain == '' || $server == '' ) return false;
$data = "";
$fp = @fsockopen($server, 43,$errno, $errstr, 5);
if( $fp ){
@fputs($fp, $domain."\r\n");
@socket_set_timeout($fp, 30);
while( !@feof($fp) ){
$data .= @fread($fp, 4096);
}
@fclose($fp);
return $data;
}else{
echo "\n\Error - could not open a connection to <b>$server</b>\n\n";
return 0;
}
}
function check_exist($output)
{
//compare what has been returned by the server
if (eregi("Can't get information",$output) || eregi("No entries found",$output) || eregi("NOT FOUND",$output) || eregi("No match",$output) ){
return 0;
}else{
return nl2br($output);
}
}
if(namecheck($domain)){
if(($output=dolookup($domain.'.'.$ext, $whoisServer))){
if(!($data=check_exist($output))){
echo"نام دامنه آزاد است";
}else{
echo"متاسفانه اين دامنه قبلا توسط شخص ديگري ثبت شده است";
}
}
}
?>