Hãy chọn Truy cập mobile | Tiếp tục

Nét Đẹp Việt Nam

 Quên mật khẩu
 Register
Xem: 2480|Trả lời: 0

PHP script to check domain age

[Lấy địa chỉ]
Đăng lúc 5-6-2014 10:41:24 | Xem tất |Chế độ đọc
PHP domain age checker script

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

Sao chép mã
Save above class as DomainAge.class.php and use following code

  1. <?
  2. require("DomainAge.class.php");
  3. $w=new DomainAge();
  4. echo $w->age("netdepviet.org");
  5. ?>
Sao chép mã
Save as domain-age-checker.php
Bạn phải đăng nhập mới được đăng bài Đăng nhập | Register

Quy tắc điểm

Phòng tối|iPhone|Archiver|G+|Youtube|Facebook|Twitter|Contact| Netdepviet.org

GMT+7, 29-3-2024 08:44 PM , Processed in 0.020029 second(s), 21 queries .

Powered by Discuz! X3.2

© 2006 Made with in Hanoi,Vietnam and Contents are published by all members

Trả lời nhanh Lên trên Trở lại danh sách