zoukankan      html  css  js  c++  java
  • php 获取域名的whois 信息

    • 首先先了解几个文件操作函数:
    •   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 . "
    ");
            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);
  • 相关阅读:
    java,for穷举,经典题目,百马百担
    《DSP using MATLAB》Problem 5.27
    《DSP using MATLAB》Problem 5.24-5.25-5.26
    《DSP using MATLAB》Problem5.23
    《DSP using MATLAB》Problem 5.22
    《DSP using MATLAB》Problem 5.21
    《金婚》截图
    《DSP using MATLAB》Problem 5.20
    《DSP using MATLAB》Problem 5.19
    《DSP using MATLAB》Problem 5.18
  • 原文地址:https://www.cnblogs.com/timelesszhuang/p/4827970.html
Copyright © 2011-2022 走看看