【问题标题】:php tool - Extracting domain names from a zone file?php 工具 - 从区域文件中提取域名?
【发布时间】:2010-05-06 14:46:33
【问题描述】:

我可以访问 tld 的区域文件。如何以最快的方式仅提取域名?

关于如何将它们存储在数据库/文件中的任何建议?数以百万计。

【问题讨论】:

    标签: php dns


    【解决方案1】:

    注意,我只是在这里敲代码。这是一般的想法,但代码可能需要编辑。事实上,几乎可以肯定。

    $fin = fopen('your zone file', 'r');
    while (!feof($fin))
    {
        $matches = array();
        $line = trim(fgets($fin));
        // only care about lines that are ip addresses or aliases
        if (preg_match('/^(\S+)\s+((?:IN\s+)?)(A|AAAA|CNAME)\s+(\S+)$/i', $line, $matches))
        {
            $subdomain = $matches[1];
            $ip_or_alias = $matches[4];
            do_something($subdomain, $ip_or_alias);
        }
    }
    fclose($fin);
    

    您将定义一个函数 do_something 来获取信息并将其存储在某处。或者,将代码放在函数调用所在的位置。

    至于如何存储它,这在很大程度上取决于您要如何处理它。

    【讨论】:

      猜你喜欢
      • 2017-01-08
      • 2013-07-19
      • 2015-01-22
      • 2021-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多