Menu

#108 Tools.pm - Implement reversed dns

open
None
5
2012-09-15
2007-11-12
No

!/usr/bin/perl

use strict;
use warnings;

use Socket qw(AF_INET);

usage() if $#ARGV == -1;
display_info( @ARGV );

sub display_info {
foreach (shift) {
my ($ip, $host, $aliases, $addrtype, $length, @addrs);
$ip = $;
if ( /^(\d+).(\d+).(\d+).(\d+)$/ ) {
print "IP is $ip\n";
($host, $aliases, $addrtype, $length, @addrs) =
gethostbyaddr( pack( 'C4', $1, $2, $3, $4 ), AF_INET );
die "Reverse lookup failed to find name for $ip\n" unless $host;
}
$host = $ip unless $host;
print "Hostname is $host\n";
($host, $aliases, $addrtype, $length, @addrs) = gethostbyname( $host );
die "Lookup failed to find address for $host\n" unless @addrs;
print "Maps to these IPs:\n";
foreach (@addrs) {
print "IP: ".join( '.', unpack( 'C4', $
) )."\n";
}
}
}

sub usage {
print STDERR <<EOM;
Usage: getdnsinfo.pl <ip|host>...
Example `getdnsinfo.pl www.interarchy.com'
EOM
exit( 0 );
}</ip|host>

Source: http://www.peter.com.au/perl/index.html

Discussion


Log in to post a comment.

MongoDB Logo MongoDB