内容显示页
 
类别:服务器相关 | 浏览(183) | 2007-9-7 20:04:09
#!/usr/bin/perl

##############################################
#
# QueryDomainNS.pl
#
# 查询域名的NS记录,是否属于万网DNS;
#
# hezhen@hichina.com
#
# builddate 2007-7-26
# 
##############################################

# ActivePerl 5.8.8.822 http://jc.newhua.com/soft/8364.htm#download
#
# UNIX下需要下载如下两个模块
# http://search.cpan.org/CPAN/authors/id/M/MA/MANU/Net-IP-1.25.tar.gz 
# http://www.net-dns.org/download/Net-DNS-0.60.tar.gz
#
# UNIX INSTALL: perl Makefile.PL && make && make install
# Win32 INSTALL: cmd --> ppm --> (这时会打开一个管理窗口,不用管它) 新开一个cmd窗口 --> ppm>install NET-IP --> ppm>install NET-DNS -->安装成功
# 使用方法:在当前文件所在的目录下新建一个"domain.txt",里面写上一行一行的网址,不带"www"的,然后开一个CMD,输入"QueryDomainNS.pl domain.txt"运行便可,运行结果会生成两个文件,运行一下就知道了。

use strict;
use Net::DNS;

my $res	= Net::DNS::Resolver->new;

if ( @ARGV != 1 ) {
	print "Usage:$0 /full_path/filename\n";
	exit(1);
}elsif(! -e "$ARGV[0]" ){
	print "$ARGV[0] no found!\n";
	exit(1);
}

my $file	= $ARGV[0];


open (FH,$file) || die ("open $file failed!\n");
while (my $domain =  ) {
	chomp $domain;

	my @ns	= '';
	my $query	= $res->query($domain,"NS");
	my $rr;
	if ($query) {
		foreach $rr ( grep { $_->type eq 'NS'} $query->answer ) {
			push(@ns,$rr->nsdname);
		}
	}else{
		QueryErrLog($domain,$res->errorstring);
	}
	
	if ( @ns[1] =~ /hichina.com/ && @ns[2] =~ /hichina.com/ ) {
		QueryResult($domain,"YES",@ns[1],@ns[2]);
	}else{
		QueryResult($domain,"NO",@ns[1],@ns[2]);
	}
}
close(FH);


# 保存查询失败结果
sub QueryErrLog {
        open( FDEF, ">>$file.QueryErrLog" ) || die "$!\n";
        flock( FDEF, 2 );
        print FDEF "$_[0]\tquery failed:$_[1]\n";
        close( FDEF );
}

# 保存查询正确结果
sub QueryResult {
	open( FDRES, ">>$file.QueryResult" ) || die "$!\n";
	flock( FDRES, 2 );
	print FDRES "$_[0]\t$_[1]\t$_[2]\t$_[3]\n";
	close( FDRES );
}

# lastupdate	yongfa365加注释 2007-9-7

引用本页地址:http://www.yongfa365.com/item/Pi-Liang-Cha-Zhao-Jie-Xi-Yu-Ming-De-DNS.html
 
 
相关链接
 
网友评论:
姓名: 记住我
网址:
邮箱:
内容:
验证码:  验证码图片 看不清? 换张图试试
 
     
 
 
文章分类
 
 
专题(3)
 
.Net + C#(41)
 
ASP+VBS(153)
 
 
 
Linux(10)
 
 
 
web 2.0(24)
 
 
 
 
 
心程(59)
 
生活(80)
 
 
     

Power by :柳永法(yongfa365)'Blog | Model by :hibaidu | CSS by:众网友 | 京ICP备07011491号  QQ:64049027  E-mail:64049027qq.com

本空间赞助商:北京中科兴联信息技术有限公司