whois域名查询代码分享

whois域名查询代码分享

<?php
$domain = $_GET['domain'];
$whoisservers = array(
    "aero"=>"whois.aero",
    "arpa" =>"whois.iana.org",
    "asia" =>"whois.nic.asia",
    "at" =>"whois.nic.at",
    "be" =>"whois.dns.be",
    "biz" =>"whois.biz",
    "br" =>"whois.registro.br",
    "ca" =>"whois.cira.ca",
    "cc" =>"whois.nic.cc",
    "cn" =>"whois.cnnic.net.cn",
    "com" =>"whois.verisign-grs.com",
    "gov" =>"whois.nic.gov",
    "in" =>"whois.inregistry.net",
    "co.in" =>"whois.inregistry.net",
    "net.in" =>"whois.inregistry.net",
    "org.in" =>"whois.inregistry.net",
    "ind.in" =>"whois.inregistry.net",
    "firm.in" =>"whois.inregistry.net",
    "info" =>"whois.afilias.info",
    "int" =>"whois.iana.org",
    "is" =>"whois.isnic.is",
    "it" =>"whois.nic.it",
    "jobs" =>"jobswhois.verisign-grs.com",
    "me" =>"whois.meregistry.net",
    "mil" =>"whois.nic.mil",
    "mobi" =>"whois.dotmobiregistry.net",
    "museum" =>"whois.museum",
    "name" =>"whois.nic.name",
    "net" =>"whois.verisign-grs.net",
    "org" =>"whois.pir.org",
    "pro" =>"whois.registrypro.pro",
    "tc" =>"whois.adamsnames.tc",
    "tel" =>"whois.nic.tel",
    "travel" =>"whois.nic.travel",
    "tv" => "whois.www.tv",
    "co.uk" =>"whois.nic.uk",
    "org.uk" =>"whois.nic.uk",
    "us" =>"whois.nic.us",
    "ws" =>"whois.website.ws");

function LookupDomain($domain){
    global $whoisservers;
    $whoisserver = "";

    $dotpos=strpos($domain,".");
    $domtld=substr($domain,$dotpos+1);

    $whoisserver = $whoisservers[$domtld];

    if(!$whoisserver) {
        return "Error: No appropriate Whois server found for <b>$domain</b> domain!";
    }
    $result = QueryWhoisServer($whoisserver, $domain);
    if(!$result) {
        return "Error: No results retrieved $domain !";
    }

    preg_match("/Whois Server: (.*)/", $result, $matches);
    $secondary = $matches[1];
    if($secondary) {
        $result = QueryWhoisServer($secondary, $domain);
    }
        return  $result;
}

function QueryWhoisServer($whoisserver, $domain) {
    $port = 43;
    $timeout = 10;
    $fp = @fsockopen($whoisserver, $port, $errno, $errstr, $timeout) or die("Socket Error " . $errno . " - " . $errstr);
    fputs($fp, $domain . "\r\n");
    $out = "";
    while(!feof($fp)){
        $out .= fgets($fp);
    }
    fclose($fp);
    return $out;
}
?>
<html>
<head>
<title>在线域名WHOIS查询(whoisabc)</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<body>
<form action="<?php $_SERVER['PHP_SELF'];?>">
  <p><b><label for="domain">查询域名:</label></b>
  <input type="text" name="domain" id="domain" autocomplete="off" title="cnyinxingshu.com">
  <input type="submit" value="我要查询">  
   </p>
</form>
<?php
if($domain) {
    if(!preg_match("/^([-a-z0-9]{2,100})\.([a-z\.]{2,8})$/i", $domain)) {
        die("查询域名WHOIS格式, 比如. <i>cnyinxingshu.com</i>!");
    }
    $result = LookupDomain($domain);
    echo "<pre>\n" . $result . "\n</pre>\n";
}
?>
</body>
</html>

演示:http://www.ssyqdq.cn

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值