PHP whois用戶端查詢的實現代碼

來源:互聯網
上載者:User
  1. /**

  2. * whois資訊查詢
  3. * by bbs.it-home.org
  4. */
  5. function ae_whois($query, $server)
  6. {
  7. define('AE_WHOIS_TIMEOUT', 15); // connection timeout
  8. global $ae_whois_errno, $ae_whois_errstr;

  9. // connecting

  10. $f = fsockopen($server, 43, $ae_whois_errno, $ae_whois_errstr, AE_WHOIS_TIMEOUT);
  11. if (!$f)
  12. return false; // connection failed

  13. // sending query

  14. fwrite($f, $query."\r\n");

  15. // receving response

  16. $response = '';
  17. while (!feof($f))
  18. $response .= fgets($f, 1024);

  19. // closing connection

  20. fclose($f);

  21. return $response;

  22. }
  23. ?>
複製代碼

以上代碼,實現了一個whois查詢函數,包括兩個參數$query(whois查詢資訊)、$server(網域名稱伺服器)。該函數返回伺服器的響應資訊,失敗則返回false。fsockopen錯誤碼與錯誤訊息,將寫入到全域變數$ae_whois_errno與$ae_whois_errstr中。大家可以更改常量AE_WHOIS_TIMEOUT來設定查詢逾時時間。

例子,用於擷取網域名稱jbxue.com的網域名稱伺服器資訊。代碼:

  1. // whois 資訊查詢
  2. echo ae_whois('jbxue.com', 'whois.verisign-grs.com');
  3. ?>
複製代碼您可能感興趣的文章:PHP擷取網域名稱的幾個全域變數php 實現dns網域名稱查詢的方法詳解(圖文)php 從url中擷取網域名稱的執行個體代碼php擷取網站的來路網域名稱的方法探討:PHP擷取網域名稱及網域名稱IP地址的方法php擷取URL中domain網域名稱的代碼一例PHP正則匹配擷取URL中網域名稱的代碼PHP擷取當前網址及網域名稱的代碼phpRegex匹配URL中的網域名稱PHP調用萬網介面實現網域名稱查詢的功能
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.