dongqiao3927 2010-05-06 14:46
浏览 22
已采纳

php工具 - 从区域文件中提取域名?

i have access to the zone file for a tld. How can I extract just the domain names in the fastest possible way?

Any suggestions on how to store them in a database/file? There are millions of them.

  • 写回答

1条回答 默认 最新

  • dongyanju0945 2010-05-06 15:27
    关注

    Note, i'm just rattling off code here. This would be the general idea, but the code may need editing. In fact, it almost certainly does.

    $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);
    

    You'd define a function do_something that would take the info and store it somewhere. Or, put the code right there where the function call is instead.

    As for how to store it, that depends a lot on what you're going to do with it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?