查看: 220|回复: 0

[PHP学习] PHP查询域名年龄脚本类

发表于 7 天前
如果我们需要自己做一个域名查询年龄的脚本可以使用下面的脚本。
  1. class DomainAge{
  2. private $WHOIS_SERVERS=array(
  3. “com” => array(“whois.verisign-grs.com”,”/Creation Date:(.*)/”),
  4. “net” => array(“whois.verisign-grs.com”,”/Creation Date:(.*)/”),
  5. “org” => array(“whois.pir.org”,”/Created On:(.*)/”),
  6. “info” => array(“whois.afilias.info”,”/Created On:(.*)/”),
  7. “biz” => array(“whois.neulevel.biz”,”/Domain Registration Date:(.*)/”),
  8. “us” => array(“whois.nic.us”,”/Domain Registration Date:(.*)/”),
  9. “uk” => array(“whois.nic.uk”,”/Registered on:(.*)/”),
  10. “ca” => array(“whois.cira.ca”,”/Creation date:(.*)/”),
  11. “tel” => array(“whois.nic.tel”,”/Domain Registration Date:(.*)/”),
  12. “ie” => array(“whois.iedr.ie”,”/registration:(.*)/”),
  13. “it” => array(“whois.nic.it”,”/Created:(.*)/”),
  14. “cc” => array(“whois.nic.cc”,”/Creation Date:(.*)/”),
  15. “ws” => array(“whois.nic.ws”,”/Domain Created:(.*)/”),
  16. “sc” => array(“whois2.afilias-grs.net”,”/Created On:(.*)/”),
  17. “mobi” => array(“whois.dotmobiregistry.net”,”/Created On:(.*)/”),
  18. “pro” => array(“whois.registrypro.pro”,”/Created On:(.*)/”),
  19. “edu” => array(“whois.educause.net”,”/Domain record activated:(.*)/”),
  20. “tv” => array(“whois.nic.tv”,”/Creation Date:(.*)/”),
  21. “travel” => array(“whois.nic.travel”,”/Domain Registration Date:(.*)/”),
  22. “in” => array(“whois.inregistry.net”,”/Created On:(.*)/”),
  23. “me” => array(“whois.nic.me”,”/Domain Create Date:(.*)/”),
  24. “cn” => array(“whois.cnnic.cn”,”/Registration Date:(.*)/”),
  25. “asia” => array(“whois.nic.asia”,”/Domain Create Date:(.*)/”),
  26. “ro” => array(“whois.rotld.ro”,”/Registered On:(.*)/”),
  27. “aero” => array(“whois.aero”,”/Created On:(.*)/”),
  28. “nu” => array(“whois.nic.nu”,”/created:(.*)/”)
  29. );
  30. public function age($domain)
  31. {
  32. $domain = trim($domain); //remove space from start and end of domain
  33. if(substr(strtolower($domain), 0, 7) == “http://”) $domain = substr($domain, 7); // remove http:// if included
  34. if(substr(strtolower($domain), 0, 4) == “www.”) $domain = substr($domain, 4);//remove www from domain
  35. if(preg_match(“/^([-a-z0-9]{2,100})\.([a-z\.]{2,8})$/i”,$domain))
  36. {
  37. $domain_parts = explode(“.”, $domain);
  38. $tld = strtolower(array_pop($domain_parts));
  39. if(!$server=$this->WHOIS_SERVERS[$tld][0]) {
  40. return false;
  41. }
  42. $res=$this->queryWhois($server,$domain);
  43. if(preg_match($this->WHOIS_SERVERS[$tld][1],$res,$match))
  44. {
  45. date_default_timezone_set(‘UTC’);
  46. $time = time() – strtotime($match[1]);
  47. $years = floor($time / 31556926);
  48. $days = floor(($time % 31556926) / 86400);
  49. if($years == “1”) {$y= “1 year”;}
  50. else {$y = $years . ” years”;}
  51. if($days == “1”) {$d = “1 day”;}
  52. else {$d = $days . ” days”;}
  53. return “$y, $d”;
  54. }
  55. else
  56. return false;
  57. }
  58. else
  59. return false;
  60. }
  61. private function queryWhois($server,$domain)
  62. {
  63. $fp = @fsockopen($server, 43, $errno, $errstr, 20) or die(“Socket Error ” . $errno . ” – ” . $errstr);
  64. if($server==”whois.verisign-grs.com”)
  65. $domain=”=”.$domain;
  66. fputs($fp, $domain . “\r\n”);
  67. $out = “”;
  68. while(!feof($fp)){
  69. $out .= fgets($fp);
  70. }
  71. fclose($fp);
  72. return $out;
  73. }
  74. }
复制代码


如何使用?

  1. require(“DomainAge.class.php”);
  2. $w=new DomainAge();
  3. echo $w->age(“laodong.me”);
复制代码
本文链接:


回复

使用道具 举报