A
Ani
Hi All,
If I use the following script to get ip address if i supply a hostname
& vice-versa:
---------------------------------------------------------------------------
#!/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 );
}
---------------------------------------------------------------------------
When I execute with the following cmdline:
$ perl getdnsinfo.pl netscape.com
then I get the following output:
Hostname is netscape.com
Maps to these IPs:
IP: 152.163.211.51
but when I execute with the ip address I got from this output:
$ perl getdnsinfo.pl 152.163.211.51
then I am getting the following output:
Hostname is nscp-rtc-vipb.websys.aol.com
Maps to these IPs:
IP: 152.163.211.51
I am unable to get the original hostname 'netscape.com' instead of
'nscp-rtc-vipb.websys.aol.com'.
How can I get the original hostname?
Any help will be highly appreciated.
~ Ani
If I use the following script to get ip address if i supply a hostname
& vice-versa:
---------------------------------------------------------------------------
#!/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 );
}
---------------------------------------------------------------------------
When I execute with the following cmdline:
$ perl getdnsinfo.pl netscape.com
then I get the following output:
Hostname is netscape.com
Maps to these IPs:
IP: 152.163.211.51
but when I execute with the ip address I got from this output:
$ perl getdnsinfo.pl 152.163.211.51
then I am getting the following output:
Hostname is nscp-rtc-vipb.websys.aol.com
Maps to these IPs:
IP: 152.163.211.51
I am unable to get the original hostname 'netscape.com' instead of
'nscp-rtc-vipb.websys.aol.com'.
How can I get the original hostname?
Any help will be highly appreciated.
~ Ani