Skip to content

Instantly share code, notes, and snippets.

@ywindish
Created July 24, 2012 01:37
Show Gist options
  • Save ywindish/3167392 to your computer and use it in GitHub Desktop.
Save ywindish/3167392 to your computer and use it in GitHub Desktop.
標準入力から与えられたIPアドレスのリストを逆引きして出力する
# 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