Home  >  Article  >  Backend Development  >  Implementation code of PHP whois client query

Implementation code of PHP whois client query

WBOY
WBOYOriginal
2016-07-25 08:56:43978browse
  1. /**

  2. * Whois information query
  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."rn");

  15. // receiving response

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

  19. // closing connection

  20. fclose($f);
  21. return $response;

  22. }
  23. ?>
Copy code

The above code implements a whois query function, including two parameters $query (whois Query information), $server (domain name server). This function returns the server's response information, or returns false if it fails. The fsockopen error code and error message will be written to the global variables $ae_whois_errno and $ae_whois_errstr. You can change the constant AE_WHOIS_TIMEOUT to set the query timeout.

Example, used to obtain the domain name server information of the domain name jbxue.com. Code:

  1. //whois information query
  2. echo ae_whois('jbxue.com', 'whois.verisign-grs.com');
  3. ?>
Copy code
Articles you may be interested in: PHP obtains several global variables of the domain name Detailed explanation of how to implement dns domain name query in php (pictures and text) php example code to get domain name from url How to get the source domain name of the site with php Discuss: How to obtain domain name and domain name IP address with PHP An example of using php to obtain the domain name code in the URL PHP regular matching to obtain the code of the domain name in the URL PHP gets the code of the current website and domain name php regular expression matching domain name in URL PHP calls Wanwang interface to implement domain name query function


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn