PHP code for whois query

WBOY
Release: 2016-07-25 08:42:42
Original
1395 people have browsed it

Use the following function to get complete details of any domain user

  1. function whois_query($domain) {
  2. // fix the domain name:
  3. $domain = strtolower(trim($domain));
  4. $domain = preg_replace('/^http:///i', '', $domain);
  5. $domain = preg_replace('/^www./i', '', $domain);
  6. $domain = explode(' /', $domain);
  7. $domain = trim($domain[0]);
  8. // split the TLD from domain name
  9. $_domain = explode('.', $domain);
  10. $lst = count( $_domain)-1;
  11. $ext = $_domain[$lst];
  12. // You find resources and lists
  13. // like these on wikipedia:
  14. //
  15. // http://de.wikipedia.org/ wiki/Whois
  16. //
  17. $servers = array(
  18. "biz" => "whois.neulevel.biz",
  19. "com" => "whois.internic.net",
  20. "us" => " whois.nic.us",
  21. "coop" => "whois.nic.coop",
  22. "info" => "whois.nic.info",
  23. "name" => "whois.nic.name ",
  24. "net" => "whois.internic.net",
  25. "gov" => "whois.nic.gov",
  26. "edu" => "whois.internic.net",
  27. "mil " => "rs.internic.net",
  28. "int" => "whois.iana.org",
  29. "ac" => "whois.nic.ac",
  30. "ae" => " whois.uaenic.ae",
  31. "at" => "whois.ripe.net",
  32. "au" => "whois.aunic.net",
  33. "be" => "whois.dns.be ",
  34. "bg" => "whois.ripe.net",
  35. "br" => "whois.registro.br",
  36. "bz" => "whois.belizenic.bz",
  37. "ca " => "whois.cira.ca",
  38. "cc" => "whois.nic.cc",
  39. "ch" => "whois.nic.ch",
  40. "cl" => " whois.nic.cl",
  41. "cn" => "whois.cnnic.net.cn",
  42. "cz" => "whois.nic.cz",
  43. "de" => "whois.nic .de",
  44. "fr" => "whois.nic.fr",
  45. "hu" => "whois.nic.hu",
  46. "ie" => "whois.domainregistry.ie",
  47. "il" => "whois.isoc.org.il",
  48. "in" => "whois.ncst.ernet.in",
  49. "ir" => "whois.nic.ir",
  50. " mc" => "whois.ripe.net",
  51. "to" => "whois.tonic.to",
  52. "tv" => "whois.tv",
  53. "ru" => "whois .ripn.net",
  54. "org" => "whois.pir.org",
  55. "aero" => "whois.information.aero",
  56. "nl" => "whois.domain-registry. nl"
  57. );
  58. if (!isset($servers[$ext])){
  59. die('Error: No matching nic server found!');
  60. }
  61. $nic_server = $servers[$ext];
  62. $output = '';
  63. // connect to whois server:
  64. if ($conn = fsockopen ($nic_server, 43)) {
  65. fputs($conn, $domain."rn");
  66. while(! feof($conn)) {
  67. $output .= fgets($conn,128);
  68. }
  69. fclose($conn);
  70. }
  71. else { die('Error: Could not connect to ' . $nic_server . '! '); }
  72. return $output;
  73. }
Copy code

Usage:

  1. $domain = "http://www.open-open.com";
  2. $result = whois_query($domain);
  3. print_r($result);
  4. ?> ;
Copy code

whois, PHP


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template