Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2147644
  • 博文数量: 227
  • 博客积分: 10521
  • 博客等级: 上将
  • 技术积分: 3452
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-20 14:59
个人简介

低调做人,高调做事!

文章分类

全部博文(227)

文章存档

2013年(4)

2012年(8)

2011年(16)

2010年(24)

2009年(92)

2008年(83)

分类: LINUX

2008-12-10 23:26:57

例子如下:

#!/usr/bin/perl -w

use strict;
use Net::DNS;


# Look up a host's addresses.

my $res   = Net::DNS::Resolver->new;
my $query = $res->search("");

if ($query) {
    foreach my $rr ( grep { $rr->type eq "A" } $query->answer ) {
        print $rr->address, "\n";
    }
}
else {
    warn "query failed: ", $res->errorstring, "\n";
}


# Find the nameservers for a domain.

my $res   = Net::DNS::Resolver->new;
my $query = $res->query( "qq.com", "NS" );

if ($query) {
    foreach my $rr ( grep { $_->type eq 'NS' } $query->answer ) {
        print $rr->nsdname, "\n";
    }
}
else {
    warn "query failed: ", $res->errorstring, "\n";
}


# Find the MX records for a domain.

my $res   = Net::DNS::Resolver->new;
my $name = "qq.com";
my @mx   = mx( $res, $name );

if (@mx) {
    foreach my $rr (@mx) {
        print $rr->preference, " ", $rr->exchange, "\n";
    }
}
else {
    warn "Can't find MX records for $name: ", $res->errorstring, "\n";
}


# Print a domain's SOA record in zone file format.

my $res   = Net::DNS::Resolver->new;
my $query = $res->query( "qq.com", "SOA" );

if ($query) {
    ( $query->answer )[0]->print;
}
else {
    print "query failed: ", $res->errorstring, "\n";
}



很简单,每个注释下的内容可以独立出来使用。

阅读(2492) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~