2012-08-25 45 views
0

我想整合一个API与我的网站之一,这是我的高级给出的任务。API是关于搜索域名已经存在与否..请帮助我在这个问题上 请给我一个例子,我可以参考。我的网站是在PHP中。域注册表api集成在php

回答

1

[编辑2]作为@Poe提到了他的意见,gethostbyname可能是一个更好的解决方案,因为它适用于任何顶级域名,因为它执行DNS查询,而不是使用whois查询,也更易于实施和可能更快:

<?php 
$ip = gethostbyname('example.com'); 
if (strstr($ip,"example.com")){ 
    echo "No match for domain example.com<br />\n"; 
} else { 
    echo "Domain found. Query output: <br />\n".$ip; 
} 
?> 

反正域名可以注册,但它不与任何计算机(例如,虽然这是非常罕见的,你可能会得到www.example.com而不是例如分辨率。 com)

[编辑]我以前没有发布过这个消息,因为我在连接到端口43上的whois.internic.net以执行whois查询时遇到了一些问题(以为他们已经关闭了该服务)。无论如何,这是一个基于fsockopen的解决方案,我认为它比我在使用CGI web脚本之前给出的解决方案好得多,也更简单。希望它可以帮助(用法:myqueryscript.php域= domainiwanttocheck.com?):

<?php 
$fp = fsockopen("199.7.58.74", 43, $errno, $errstr, 30); 
if (!$fp) { 
    echo "$errstr ($errno)<br />\n"; 
} else { 
    $query = $_GET['domain']."\r\n"; 
    $answer= ''; 
    fwrite($fp, $query); 
    while (!feof($fp)) { 
     $answer .= fgets($fp, 128)."<br />"; 
    } 
    fclose($fp); 
    if (strstr($answer,"No match for")){ 
     echo "No match for domain ".$_GET['domain']."<br />\n"; 
    } else { 
     echo "Domain found. Query output: <br />\n".$answer; 
    } 
} 
?> 

从InterNIC的网站,这是HTML代码来实现的whois查询:

<form method="get" action="http://reports.internic.net/cgi/whois" name="my_form"> 
      <input type="text" size="30" name="whois_nic" maxlength="80"> 
      <br> 
      <input type="radio" name="type" value="domain" checked> 
      Domain<font size="-1"> (ex. internic.net) 
      <br> 
      <input type="radio" name="type" value="registrar"> 
      Registrar<font size="-1"> (ex. ABC Registrar, Inc.) 
      <br> 
      <input type="radio" name="type" value="nameserver"> 
      Nameserver (ex. NS.EXAMPLE.COM or 192.16.0.192)<br> 
      <br> 
      <input type="submit" value="Submit"> 
    </form> 

这意味着你可以发送一个像这样的whois查询:http://reports.internic.net/cgi/whois?whois_nic=domainiwanttocheck.com&type=domain

您可以从脚本发送查询并将响应存储在DOMDocument对象上。检出:http://www.php.net/manual/en/domdocument.loadhtml.php

如果您使用此方法查找域并且域不存在,您将得到字符串No match for domain。使用strpos

如果该域存在的反应看这一点,您可以过滤响应包括有关注册机构的信息等,这将是HTML标签的响应<pre>的内容:

<pre> 

Whois Server Version 2.0 

Domain names in the .com and .net domains can now be registered 
with many different competing registrars. Go to http://www.internic.net 
for detailed information. 

    Domain Name: GOOGLE.COM 
    Registrar: MARKMONITOR INC. 
    Whois Server: whois.markmonitor.com 
    Referral URL: http://www.markmonitor.com 
    Name Server: NS1.GOOGLE.COM 
    Name Server: NS2.GOOGLE.COM 
    Name Server: NS3.GOOGLE.COM 
    Name Server: NS4.GOOGLE.COM 
    Status: clientDeleteProhibited 
    Status: clientTransferProhibited 
    Status: clientUpdateProhibited 
    Status: serverDeleteProhibited 
    Status: serverTransferProhibited 
    Status: serverUpdateProhibited 
    Updated Date: 20-jul-2011 
    Creation Date: 15-sep-1997 
    Expiration Date: 14-sep-2020 

>>> Last update of whois database: Sat, 25 Aug 2012 10:15:09 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. 
     </pre> 

另外,看看这个相关的问题:Who provides a WHOIS API?

+1

最好不要使用过时的''元素! – ComFreek

+0

ohh ..非常感谢你,我现在有点关于api集成的想法..可以请你解释一些重要的事情,比如它是如何工作的,什么是功能,什么是代码使用这个api这样的..所以我可以修改它,并学习一些东西 –

+0

我更新了我的问题,包括一些关于如何从PHP脚本进行查询并将响应存储在DOMDocument对象上的提示。关于API,它有很好的文档记录。阅读有关如何在此处使用它的信息:http://www.whoisxmlapi.com/whois-api-doc.php – NotGaeL