php 擷取網域名稱的whois 資訊

來源:互聯網
上載者:User

標籤:

  • 首先先瞭解幾個檔案操作函數:
  •   fwrite() 函數寫入檔案(可安全用於二進位檔案)。

  fwrite() 把 string 的內容寫入檔案指標 file 處。 如果指定了 length,當寫入了 length 個位元組或者寫完了 string 以後,寫入就會停止,視乎先碰到哪種情況。 fwrite() 返回寫入的字元數,出現錯誤時則返回 false。

  <?php  $file = fopen("test.txt","w");  echo fwrite($file,"Hello World. Testing!");  fclose($file);  ?>

 

  •   feof(file) 函數檢測是否已到達檔案末尾 (eof)。

  如果檔案指標到了 EOF 或者出錯時則返回 TRUE, 否則返回一個錯誤(包括 socket 逾時),其它情況則返回 FALSE。 file 參數是一個檔案指標。這個檔案指標必須有效,並且必須指向一個由 fopen() 或 fsockopen() 成功開啟(但還沒有被 fclose() 關閉)的檔案。
  提示:feof() 函數對遍曆長度未知的資料很有用。
  注意:如果伺服器沒有關閉由 fsockopen() 所開啟的串連,feof() 會一直等待直到逾時而返回 TRUE。預設的逾時限制是 60 秒,可以使用 stream_set_timeout() 來改變這個值。
  注意:如果傳遞的檔案指標無效可能會陷入無限迴圈中,因為 EOF 不會返回 TRUE。

  <?php  $file = fopen("test.txt", "r");  //輸出文本中所有的行,直到檔案結束為止。  while(! feof($file)){  echo fgets($file). "<br />";  }W  fclose($file);  ?>

 

  •   fputs() 函數寫入檔案(可安全用於二進位檔案)。fputs() 函數是 fwrite() 函數的別名。

  fputs(file,string,length)

  <?php  $file = fopen("test.txt","w");  echo fputs($file,"Hello World. Testing!");  fclose($file);  ?>

 

  •   fgets() 從 file 指向的檔案中讀取一行並返回長度最多為 length - 1 位元組的字串。碰到分行符號(包括在傳回值中)、EOF 或者已經讀取了 length - 1 位元組後停止(要看先碰到那一種情況)。如果沒有指定 length,則預設為 1K,或者說 1024 位元組。若失敗,則返回 false。
  <?php  $file = fopen("test.txt","r");  while(! feof($file))  {  echo fgets($file). "<br />";  }  fclose($file);  ?>
  •   fgetss() 函數從開啟的檔案中讀取一行並過濾掉 HTML 和 PHP 標記。與 fgets() 相同,不同的是 fgetss 嘗試從讀取的文本中去掉任何 HTML 和 PHP 標記。

           fgetss(file,length,tags)    可以用可選的第三個參數 tags 指定哪些標記不被去掉。若失敗,則返回 false。

  <?php  $file = fopen("test.htm","r");  echo fgetss($file,1024,"<p>,<b>");  fclose($file);  ?>

以下是擷取whois 資訊的代碼

function whois_query($domain) {    // fix the domain name:    $domain = strtolower(trim($domain));    $domain = preg_replace(‘/^http:\/\//i‘, ‘‘, $domain);    $domain = preg_replace(‘/^www\./i‘, ‘‘, $domain);    $domain = explode(‘/‘, $domain);    $domain = trim($domain[0]);    // split the TLD from domain name    $_domain = explode(‘.‘, $domain);    $lst = count($_domain) - 1;    $ext = $_domain[$lst];    // You find resources and lists     // like these on wikipedia:     // http://de.wikipedia.org/wiki/Whois    $servers = array(        "biz" => "whois.neulevel.biz",        "com" => "whois.internic.net",        "us" => "whois.nic.us",        "coop" => "whois.nic.coop",        "info" => "whois.nic.info",        "name" => "whois.nic.name",        "net" => "whois.internic.net",        "gov" => "whois.nic.gov",        "edu" => "whois.internic.net",        "mil" => "rs.internic.net",        "int" => "whois.iana.org",        "ac" => "whois.nic.ac",        "ae" => "whois.uaenic.ae",        "at" => "whois.ripe.net",        "au" => "whois.aunic.net",        "be" => "whois.dns.be",        "bg" => "whois.ripe.net",        "br" => "whois.registro.br",        "bz" => "whois.belizenic.bz",        "ca" => "whois.cira.ca",        "cc" => "whois.nic.cc",        "ch" => "whois.nic.ch",        "cl" => "whois.nic.cl",        "cn" => "whois.cnnic.net.cn",        "cz" => "whois.nic.cz",        "de" => "whois.nic.de",        "fr" => "whois.nic.fr",        "hu" => "whois.nic.hu",        "ie" => "whois.domainregistry.ie",        "il" => "whois.isoc.org.il",        "in" => "whois.ncst.ernet.in",        "ir" => "whois.nic.ir",        "mc" => "whois.ripe.net",        "to" => "whois.tonic.to",        "tv" => "whois.tv",        "ru" => "whois.ripn.net",        "org" => "whois.pir.org",        "aero" => "whois.information.aero",        "nl" => "whois.domain-registry.nl"    );    if (!isset($servers[$ext])) {        die(‘Error: No matching nic server found!‘);    }    $nic_server = $servers[$ext];    $output = ‘‘;    // connect to whois server:    if ($conn = fsockopen($nic_server, 43)) {        fputs($conn, $domain . "\r\n");        while (!feof($conn)) {            $output .= fgets($conn, 128);        }        fclose($conn);    } else {        die(‘Error: Could not connect to ‘ . $nic_server . ‘!‘);    }    return $output;}$domain = ‘www.qiangbi.net/a.html‘;$output = whois_query($domain);print_r($output);

 

php 擷取網域名稱的whois 資訊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.