用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - perl代码库

perl 简单的DNS查找

2012-10-15 作者: 神马举报

[perl]代码库

#-----------------------------
use Socket;

@addresses = gethostbyname ( $name )   or die "Can't resolve $name: $!\n";
@addresses = map { inet_ntoa ( $_ ) } @addresses[4 .. $#addresses];
# @addresses is a list of IP addresses ("208.201.239.48", "208.201.239.49")
#-----------------------------
use Socket;

$address = inet_ntoa ( inet_aton ( $name ) );
# $address is a single IP address "208.201.239.48"
#-----------------------------
use Socket;

$name = gethostbyaddr ( inet_aton ( $address ), AF_INET )
        or die "Can't resolve $address: $!\n";
# $name is the hostname ("www.perl.com")
#-----------------------------
use Socket;
$packed_address = inet_aton ( "208.146.140.1" );
$ascii_address  = inet_ntoa ( $packed_address );
#-----------------------------
$packed = gethostbyname ( $hostname )
          or die "Couldn't resolve address for $hostname: $!\n";
$address = inet_ntoa ( $packed );
print "I will use $address as the address for $hostname\n";
#-----------------------------
# $address is the IP address I'm checking, like "128.138.243.20"
use Socket;
$name    = gethostbyaddr(inet_aton($address), AF_INET)
           or die "Can't look up $address : $!\n";
@addr    = gethostbyname($name)
           or die "Can't look up $name : $!\n";
$found   = grep { $address eq inet_ntoa($_) } @addr[4..$#addr];
#-----------------------------
# download the following standalone program
#!/usr/bin/perl
# mxhost - find mx exchangers for a host
use Net::DNS;

$host = shift;
$res = Net::DNS::Resolver->new();
@mx = mx($res, $host)
      or die "Can't find MX records for $host ( ".$res->errorstring," ) \n";

foreach $record (@mx) {
	print $record->preference, " ", $record->exchange, "\n";
}

#-----------------------------
#% mxhost cnn.com
#10 mail.turner.com
#
#30 alfw2.turner.com
#-----------------------------
# download the following standalone program
#!/usr/bin/perl
# hostaddrs - canonize name and show addresses
use Socket;
use Net::hostent;
$name = shift;
if ($hent = gethostbyname($name)) {
$name      = $hent->name;                # in case different
		$addr_ref  = $hent->addr_list;
	@addresses = map { inet_ntoa($_) } @$addr_ref;
}
print "$name => @addresses\n";

#-----------------------------
#% hostaddrs www.ora.com
#helio.ora.com => 204.148.40.9
#
#
#% hostaddrs www.whitehouse.gov
#www.whitehouse.gov => 198.137.240.91 198.137.240.92
#-----------------------------


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...