Created
July 24, 2012 01:37
-
-
Save ywindish/3167392 to your computer and use it in GitHub Desktop.
標準入力から与えられたIPアドレスのリストを逆引きして出力する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DNS PTR record lookup | |
# 標準入力から与えられたIPアドレスのリストを逆引きして出力する | |
use strict; | |
use Net::DNS; | |
my $resolver = Net::DNS::Resolver->new(); | |
while (<>) { | |
chomp; | |
my $ipaddress = $_; | |
my $query = $resolver->search($ipaddress, 'PTR'); | |
unless ($query) { | |
print $ipaddress."\t\n"; | |
next; | |
} | |
my $hostname = ''; | |
foreach my $rr ($query->answer()) { | |
if ($rr->type eq 'PTR') { | |
$hostname = $rr->ptrdname; | |
last; | |
} | |
} | |
print $ipaddress."\t".$hostname."\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment