码迷,mamicode.com
首页 > 其他好文 > 详细

dig域名

时间:2015-08-04 23:19:04      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:dig域名

#!/usr/bin/perl

#use warnings;
use strict;
use Parallel::ForkManager;
use JSON::XS;
use Net::DNS::Nslookup;
use Net::Nslookup;
use POSIX qw(strftime);
use Digest::MD5;

`[ -d ./logs ] || mkdir logs`;
my $listPath = "./domain-list";
my $dropPath = "./domain-drop";
my $logsPath = "./logs/";

our $dmList = {};
our $time   = time;

open IN, "$listPath";
open my $DRP, "> $dropPath";
my  $pm = Parallel::ForkManager->new(50);
while (<IN>){
  my $res = $_;
  my $rr  = ‘‘;
  chomp $res;
  $pm->start and next;
     my @fields = split(",", $res);
     if(defined $fields[0] && defined $fields[1]) {
       my $domain = "$fields[0].lv$fields[1].cloudglb.com";      
       $rr = $fields[1] eq 3 ? getArr($domain) : getCname($domain);   
       print "==[$rr]=$domain==\n";
       if($rr eq 0){
          syswrite $DRP ,"${domain}\n";
       }
     }
  $pm->finish;
}
$pm->wait_all_children;
close IN;
close $DRP;

dmJson("$dropPath");
my $toPost  = JSON::XS->new->encode($dmList);
open  OUT, "> ${logsPath}${time}";
print OUT $toPost;
close OUT;

my $tokenUrl = token();
print "==$tokenUrl==\n";
#`wget --post-file=${logsPath}${time} http://****/${tokenUrl}/  -SO /server/script/logs/out-$time`;

sub dmJson() {
  my   $dmFile = shift;
  open RES, "$dmFile";
  while (<RES>) {
    my $dmName = $_;
    chomp $dmName;
    next  if $dmName eq "";
    $dmList->{"$dmName"} = "${time}";
  }
  close RES;
  return $dmList;
}

sub getCname {
    my $dmName = shift;
    my @digRes = nslookup(host=>$dmName, type=>"CNAME");
       return @digRes ? 1 : 0;
}

sub getArr {
    my $dmName = shift;
    my $rr = Net::DNS::Nslookup->get_ips($dmName);
       return $rr eq ‘‘ ? 0 : 1;
}

sub token(){
  my $day = strftime "%Y%m%d", localtime(time);
  my $md5 = Digest::MD5->new;
     $md5->add(‘hello world!!!!!‘);
  my $tmd5= $md5->hexdigest;
     $md5->add("$day$tmd5");
  return $md5->hexdigest;
}


本文出自 “技术屌丝” 博客,谢绝转载!

dig域名

标签:dig域名

原文地址:http://yeqing.blog.51cto.com/3159086/1681655

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!