当前位置:首页 > PHP教程 > php应用 > 列表

php查询whois信息的方法

发布:smiling 来源: PHP粉丝网  添加日期:2021-05-27 15:57:53 浏览: 评论:0 

这篇文章主要介绍了php查询whois信息的方法,涉及php域名查询的相关技巧,需要的朋友可以参考下。

本文实例讲述了php查询whois信息的方法,分享给大家供大家参考,具体如下:

这里使用php通过查询whois信息的网站列表进行查询。

  1. function whois_query($domain) { 
  2.   // fix the domain name: 
  3.   $domain = strtolower(trim($domain)); 
  4.   $domain = preg_replace('/^http:\/\//i', '', $domain); 
  5.   $domain = preg_replace('/^www\./i', '', $domain); 
  6.   $domain = explode('/', $domain); 
  7.   $domain = trim($domain[0]); 
  8.   // split the TLD from domain name 
  9.   $_domain = explode('.', $domain); 
  10.   $lst = count($_domain)-1; 
  11.   $ext = $_domain[$lst]; 
  12.   // You find resources and lists  
  13.   // like these on wikipedia:  
  14.   // 
  15.   // http://de.wikipedia.org/wiki/Whois 
  16.   // 
  17.   $servers = array( 
  18.     "biz" => "whois.neulevel.biz", 
  19.     "com" => "whois.internic.net", 
  20.     "us" => "whois.nic.us", 
  21.     "coop" => "whois.nic.coop", 
  22.     "info" => "whois.nic.info", 
  23.     "name" => "whois.nic.name", 
  24.     "net" => "whois.internic.net", 
  25.     "gov" => "whois.nic.gov", 
  26.     "edu" => "whois.internic.net", 
  27.     "mil" => "rs.internic.net", 
  28.     "int" => "whois.iana.org", 
  29.     "ac" => "whois.nic.ac", 
  30.     "ae" => "whois.uaenic.ae", 
  31.     "at" => "whois.ripe.net", 
  32.     "au" => "whois.aunic.net", 
  33.     "be" => "whois.dns.be", 
  34.     "bg" => "whois.ripe.net", 
  35.     "br" => "whois.registro.br", 
  36.     "bz" => "whois.belizenic.bz", 
  37.     "ca" => "whois.cira.ca", 
  38.     "cc" => "whois.nic.cc", 
  39.     "ch" => "whois.nic.ch", 
  40.     "cl" => "whois.nic.cl", 
  41.     "cn" => "whois.cnnic.net.cn", 
  42.     "cz" => "whois.nic.cz", 
  43.     "de" => "whois.nic.de", 
  44.     "fr" => "whois.nic.fr", 
  45.     "hu" => "whois.nic.hu", 
  46.     "ie" => "whois.domainregistry.ie", 
  47.     "il" => "whois.isoc.org.il", 
  48.     "in" => "whois.ncst.ernet.in", 
  49.     "ir" => "whois.nic.ir", 
  50.     "mc" => "whois.ripe.net", 
  51.     "to" => "whois.tonic.to", 
  52.     "tv" => "whois.tv", 
  53.     "ru" => "whois.ripn.net", 
  54.     "org" => "whois.pir.org", 
  55.     "aero" => "whois.information.aero", 
  56.     "nl" => "whois.domain-registry.nl" 
  57.   ); 
  58.   if (!isset($servers[$ext])){ 
  59.     die('Error: No matching nic server found!'); 
  60.   } 
  61.   $nic_server = $servers[$ext]; 
  62.   $output = ''; 
  63.   // connect to whois server: 
  64.   if ($conn = fsockopen ($nic_server, 43)) { 
  65.     fputs($conn, $domain."\r\n"); 
  66.     while(!feof($conn)) { 
  67.       $output .= fgets($conn,128); 
  68.     } 
  69.     fclose($conn); 
  70.   } 
  71.   else { die('Error: Could not connect to ' . $nic_server . '!'); } 
  72.   return $output; 
  73. } 
  74. // Some example queries: 
  75. print whois_query('jonasjohn.de'); 
  76. print whois_query('example.com'); 
  77. print whois_query('example.org');

Tags: php查询whois

分享到: