-1

1つのAPIを私のウェブサイトの1つと統合したいのですが、これは私の先輩から与えられたタスクです。APIは、すでに存在するかどうかに関係なくドメイン名を検索するためのものです。このトピックについて教えてください。参照できる例を教えてください。ウェブサイトはPHPです。

4

3 に答える 3

3

[編集2] @Poeがコメントで述べているように、gethostbynameは、whoisクエリの代わりにDNSクエリを実行し、実装がはるかに簡単で、おそらく高速であるため、トップレベルドメインで機能するため、おそらくはるかに優れたソリューションです。 :

<?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の解決策が得られる場合がありますが、example.comの解決策は得られない場合があります)

[編集] whoisクエリを実行するためにポート43でwhois.internic.netに接続するのに問題があったため、これを投稿しませんでした(サービスを完全にシャットダウンしたと思っていました)。とにかく、これが私がコーディングしたばかりのfsockopenベースのソリューションです。これは、CGIWebスクリプトを使用する前に提供したソリューションよりもはるかに優れていて単純だと思います。お役に立てば幸いです(使用法:myqueryscript.php?domain = 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 Webサイトから、これはwhoisクエリを実装するためのhtmlコードです。

<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 domainstrposを使用した応答でこれを探します

ドメインが存在する場合は、応答をフィルタリングして、レジストラなどに関する情報を含めることができます。これは<pre>、応答のhtmlタグのコンテンツになります。

<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>

また、この関連する質問を確認してください:WHOIS APIを提供するのは誰ですか?

于 2012-08-25T10:12:04.313 に答える
-1
<?php

if(isset($_GET['domain'])){
    $domain = $_GET['domain'];
} else {
    $domain = "";
}
$api_key = "api_key";
//domain also you can use this api http://api.neoistone.com/domain-check/?apiKey=&domainName=google.com
//if need api key contact us https://www.neoistone.com/contact-us/
//domain also your user the api https://domain-availability.whoisxmlapi.com/api/v1/?apiKey=&domainName=google.com
//if need api key contact us browser https://domain-availability.whoisxmlapi.com

$api = "https://domain-availability.whoisxmlapi.com/api/v1";
        $api .= '?apiKey='.urlencode($api_key);
        $api .= "&domainName=".urlencode($domain);
        $response = array();
        $curl = curl_init();
        curl_setopt_array($curl, array(
        CURLOPT_URL => $api,CURLOPT_RETURNTRANSFER => true,CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,CURLOPT_TIMEOUT => 30,CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "GET",CURLOPT_HTTPHEADER => array("cache-control: no-cache","postman-token: 22890b81-68a3-c75c-7dc5-1d1e6e9d1cf2"),));
        $ch_ap = json_decode(curl_exec($curl),TRUE);
        if (isset($ch_ap['messages'])) {
            $response['status'] = "error";
            $response['message'] = $ch_ap['messages'];
            $response['code'] = $ch_ap['code'];
        } else {
           $curl_response = $ch_ap['DomainInfo'];
           if ($curl_response['domainAvailability'] == "UNAVAILABLE") {
               $response['status'] = "sussfuly";
               $response['meassage'] = 'Domain is '.$domain.' unavailable ';
               $response['code'] = 200;
           } elseif ($curl_response['domainAvailability'] == "AVAILABLE") {
               $response['status'] = "sussfuly";
               $response['meassage'] = 'Domain is '.$domain.' available ';
               $response['code'] = 200;
           } else {
              $response = $curl_response;
           }
        }
        print_r($response);
        curl_close($curl);
?>
于 2020-10-30T09:41:00.580 に答える
-1

ドメイン名とTLDを取得する

<?php
$host = 'https://compute-1.hyd.in.securedatacenter.host';
preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches);
$data = explode('.',$matches['0']);

//print_r($data);
echo 'Your domain name is :- '.$data['0'].'<br>';
echo 'Your tld is :- '.$data['1'];
?>

応答プレビュー

于 2021-08-22T10:31:53.993 に答える