php whois查询API制作方法

域名查询代码公布?php// 网络技术主管座右铭:三人行,其必有我师焉。
这个代码可以是说是非常的SMART,我改动了小小部分使它更容易用。$moreinfolist
= array( // 储存WHOIS查询主机的连接方法’at’ = ”,’au’ = ”,’bm’ =
‘_query_get.pl?query_text=’,’ch’ = ‘_domain?keyword=’,’com’= ”,’cz’
= ”,’de’ = ”,’dk’ = ”,’edu’= ”,’es’ = ”,’fi’ = ”,’fo’ = ”,’fr’ =
‘harmonic.nic.fr/cgi-bin/HarmoNIC.pl?Annu_Suffixe=&Annu_Action=Rechercher&Annu_Automaton_State=17&Annu_Motif=’,’gl’
= ”,’gm’ = ”,’gov’= ”,’gr’ = ”,’hu’ = ”,’id’ =
‘whois.idnic.net.id/cgi-bin/whois-cgi?user=’,’ie’ = ”,’il’ = ”,’is’ =
”,’it’ = ”,’jp’ = ‘_gw?lang=/e&type=DOM&rule=ex&key=’,’lb’ = ”,’li’
= ‘_domain?keyword=’,’lt’ = ”,’lv’ = ”,’mc’ = ”,’mil’= ”,’ms’ =
”,’mx’ = ”,’net’= ”,’no’ = ”,’nz’ = ”,’org’= ”,’pt’ = ”,’ro’ =
‘whois.rotld.ro/cgi-bin/whois?whois=’,’sk’ = ”,’sm’ = ”,’tc’ = ”,’tf’
= ”,’th’ = ”,’tj’ = ”,’tr’ = ‘whois.cc.metu.edu.tr/whois/’,’uk’ =
”,’va’ = ”,’vg’ = ”);# where can we get more info?$moreinfo =
FALSE;for ( reset($moreinfolist) ; list($tail, $moreinfoname) =
each($moreinfolist) ; )if ( eregi(//.$tail/$, $address) ) { //
比较域名后缀$moreinfo = $moreinfoname; //
遇到匹配项就立即结束循环break;}if ( $moreinfo && $address) { //
跳转到WHOIS主机header(‘Location: ‘. $moreinfo . $address);exit();}else
{echo form action=$PHP_SELF method=post请输入域名:input
name=addressinput type=submit/form;}?htmlheadtitlewhois
tool/title/headbodyp网络技术主管汉化解释/a./phr
/address_file(whois.php);?

<div  class=contentbox>
<div class=”content_nav”><span
class=”tt”>IP/域名WHOIS查询</span></div>
<div class=toolitem>
<br>
<form action=”” method=”get”>
IP/域名:<input style=”height:26px;border: 1px solid rgb(126, 157,
185); background-color: white;” id=”query” maxlength=”100″ size=”44″
name=”q” autocomplete=”off” type=”text”
value=”<?php教程 echo $q;
?>”>
<span class=”backgroundbord”><button class=”srh_onesearch”
type=”submit”>查      询</button></span>
</form>
</div>
</div>
<?php
require_once $_SERVER[‘DOCUMENT_ROOT’].’/ad/mid.php’;
if($q2<>”){
 if($isdomain){
  echo ‘<div class=contentbox>’;
  echo ‘<div class=”content_nav”><span
class=”tt”>查询结果</span></div>’;
  echo ‘<div class=topmenuitem>’;
  // Server List File
  $config[‘server_list’] = “./whois/servers.lst”;
  whois($domain);
  echo ‘</div>’;
  echo ‘</div>’;
 }elseif($isip){
  echo ‘<div class=contentbox>’;
  echo ‘<div class=”content_nav”><span
class=”tt”>查询结果</span></div>’;
  echo ‘<div class=topmenuitem>’;
  $sourcecode=getsourcecode(“http://wq.apnic.net/apnic-bin/whois.pl?searchtext=”.$q);
  //echo $sourcecode;
  preg_match(‘/(<pre><b><u>.*?)<div
class=”highlight” id=”key”>/s’, $sourcecode, $ipwhois);
  $result=$ipwhois[1];
  $result=nl2br($result);
  echo $result;
  echo ‘</div>’;
  echo ‘</div>’;
 }else{
  echo ‘<div class=contentbox>’;
  echo ‘<div class=”content_nav”><span
class=”tt”>Error!</span></div>’;
  echo ‘<div class=topmenuitem><p><font
color=red>Error!</font>请确保你输入的不是域名(中文域名暂不支持)就是IP,你要是输入的是电话号码之类那我们真查不了!</p>’;
  echo ‘</div>’;
  echo ‘</div>’;
 }
}else{
  echo ‘<div class=contentbox>’;
  echo ‘<div class=”content_nav”><span
class=”tt”>工具说明</span></div>’;
  echo ‘<div
class=topmenuitem><p>请输入IP或域名,如chaxun.la或xxx.xxx.xxx.xxx</p>’;
  echo ‘</div>’;
  echo ‘</div>’;
}
function whois() {
 global $domain;
 if(!$server = get_server()) {
  die(“无法查询此类型的域名”);
 }
  $result = whois_request($server[‘server’], $domain);
  if(!$result) {
   echo “无法连接服务器”;
   die();
  }
  $server[‘info’]=trim($server[‘info’]);
  if($server[‘info’]){
   $he = strpos($result,$server[‘info’]) +
strlen($server[‘info’]);
   $le = strpos($result, ” “, $he);
   $whois_server = trim(substr($result, $he, $le-$he));
   $result2 = whois_request($whois_server, $domain);
   if($result2){
    echo nl2br($result.” 以下信息来自:”.$whois_server.” “.$result2);
   }else {
    echo nl2br($result);
   }
  }else {
   echo nl2br($result);
  }
}
/*function whois() {
 global $domain;
 if(!$server = get_澳门新浦京8455com ,server()) {
  echo “无法查询此类型的域名”;
 }else{
  $result = whois_request($server[‘server’], $domain);
  if(!$result) {
   echo “无法连接服务器”;
  } else {
   echo $result;
  }
 }
}
*/
function whois_request($server, $query)
{
    $data = “”;
 if(!$fp = @fsockopen($server, 43)) {
  Return false;
 } else {
  fputs($fp, $query . ” “);
        while (!feof($fp)) {
            $data .= fread($fp, 1000);
        }
        fclose($fp);
 }
    //return nl2br($data);
 return $data;
}

这里我们从万网或新网的数据接口取得数据,透过php的简单文本处理再输出。
复制代码 代码如下:
$domain = $_GET[‘q’];
preg_match(“|
(.+?)<>
|is”,
@file_get_contents(”),
$whois);
echo $whois[1];
?>

function get_server() {
 global $config,$domain;
 $serverarray = file($config[‘server_list’]);
 $i = 0;
 foreach($serverarray as $key=>$val) {
  if(substr($val,0,1) != “#”) {
   $server_p = explode(“|”,$val);
   $server[$i][‘tld’] = $server_p[0];
   $server[$i][‘server’] = $server_p[1];
   $server[$i][‘avail’] = $server_p[2];
   $server[$i][‘infoserver’] = $server_p[3];
   $server[$i][‘backserver’] = $server_p[4];
   $server[$i][‘info’] = $server_p[5];
  }
  $i++;
 }

做到这里,可能有的朋友要问了,这不就是简单的php脚本么?!哪是api接口阿;接着我们来加工一下,让查询方式更专业一些:
我们需要的查询格式如下:

其中baidu.com是需要查询的域名
可以修改nginx的配置来实现这一点:
复制代码 代码如下:
location ~* /whois/(.+)$ {
proxy_pass
#将查询传递给内网的apache处理
}

 $domain_c = explode(“.”,$domain);
 $partnum = count($domain_c);
 $last_part_1 = $domain_c[$partnum-1];
 $last_part_2 = $domain_c[$partnum-2];
 
 foreach($server as $key=>$val) {
  if($val[‘tld’] == $last_part_2.”.”.$last_part_1) {
   Return $val;
  } elseif($val[‘tld’] == $last_part_1) {
   Return $val;
  }
 }
 Return false;
}

ok,至此一个使用的whois
api接口完成了,你可以自己的程序中调用,也可以共享给大家使用^_^!。
查询baidu.com的结果:
Whois Server Version 2.0
Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to

for detailed information.
Domain Name: BAIDU.COM
Registrar: REGISTER.COM, INC.
Whois Server: whois.register.com
Referral URL:
Name Server: DNS.BAIDU.COM
Name Server: NS2.BAIDU.COM
Name Server: NS3.BAIDU.COM
Name Server: NS4.BAIDU.COM
Status: clientTransferProhibited
Status: serverDeleteProhibited
Status: serverTransferProhibited
Status: serverUpdateProhibited
Updated Date: 15-mar-2010
Creation Date: 11-oct-1999
Expiration Date: 11-oct-2014
>>> Last update of whois database: Fri, 20 Aug 2010 05:42:12
UTC <<<
NOTICE: The expiration date displayed in this record is the date the
registrar’s sponsorship of the domain name registration in the registry
is
currently set to expire. This date does not necessarily reflect the
expiration
date of the domain name registrant’s agreement with the sponsoring
registrar. Users may consult the sponsoring registrar’s Whois database
to
view the registrar’s reported date of expiration for this
registration.
TERMS OF USE: You are not authorized to access or query our Whois
database through the use of electronic processes that are high-volume
and
automated except as reasonably necessary to register domain names or
modify existing registrations; the Data in VeriSign Global Registry
Services’ (“VeriSign”) Whois database is provided by VeriSign for
information purposes only, and to assist persons in obtaining
information
about or related to a domain name registration record. VeriSign does
not
guarantee its accuracy. By submitting a Whois query, you agree to
abide
by the following terms of use: You agree that you may use this Data
only
for lawful purposes and that under no circumstances will you use this
Data
to: (1) allow, enable, or otherwise support the transmission of mass
unsolicited, commercial advertising or solicitations via e-mail,
telephone,
or facsimile; or (2) enable high volume, automated, electronic
processes
that apply to VeriSign (or its computer systems). The compilation,
repackaging, dissemination or other use of this Data is expressly
prohibited without the prior written consent of VeriSign. You agree not
to
use electronic processes that are automated and high-volume to access
or
query the Whois database except as reasonably necessary to register
domain names or modify existing registrations. VeriSign reserves the
right
to restrict your access to the Whois database in its sole discretion to
ensure
operational stability. VeriSign may restrict or terminate your access to
the
Whois database for failure to abide by these terms of use. VeriSign
reserves the right to modify these terms at any time.
The Registry database contains ONLY .COM, .NET, .EDU domains and
Registrars.
The data in Register.com’s WHOIS database is provided to you by
Register.com for information purposes only, that is, to assist you in
obtaining information about or related to a domain name registration
record. Register.com makes this information available “as is,” and
does not guarantee its accuracy. By submitting a WHOIS query, you
agree that you will use this data only for lawful purposes and that,
under no circumstances will you use this data to: (1) allow, enable,
or otherwise support the transmission of mass unsolicited, commercial
advertising or solicitations via direct mail, electronic mail, or by
telephone; or (2) enable high volume, automated, electronic processes
that apply to Register.com (or its systems). The compilation,
repackaging, dissemination or other use of this data is expressly
prohibited without the prior written consent of Register.com.
Register.com reserves the right to modify these terms at any time.
By submitting this query, you agree to abide by these terms.
Registrant:
Beijing Baidu Netcom Science and Technology Co.Ltd.
Baidu Netcom Baidu Netcom
No. 10, Shangdi 10th Street, Haidian District,
Beijing, 100085
CN
Phone: +86.1059926680
Email: domainmaster@baidu.com
Registrar Name….: Register.com
Registrar Whois…: whois.register.com
Registrar Homepage: www.register.com
Domain Name: baidu.com
Created on…………..: 1999-10-11
Expires on…………..: 2014-10-11
Administrative Contact:
Beijing Baidu Netcom Science and Technology Co.Ltd.
Baidu Netcom Baidu Netcom
No. 10, Shangdi 10th Street, Haidian District,
Beijing, 100085
CN
Phone: +86.1059927440
Email: wumengyi@baidu.com
Technical Contact:
Registercom
Domain Registrar
575 8th Avenue
New York, NY 10018
US
Phone: +1.9027492701
Email: domainregistrar@register.com
DNS Servers:
ns3.baidu.com
ns2.baidu.com
ns4.baidu.com
dns.baidu.com
Visit AboutUs.org for more information about baidu.com
AboutUs: baidu.com
Register your domain name at

$q=trim($_GET[‘q’]);
$q2=$q;
if($q<>”){
if($q=matchip($q2)){
  $isip=1;
 }elseif($q=matchdomain($q2)){
  $domain=topdomain($q2);
  $isdomain=1;
 }
}澳门新浦京8455com 1

You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图