in reply to please help - c shell in perl
This doesn't necessarily use the DNS. It depends on how your system is set up (if you are on some types of UNIX you can look at your /etc/nsswitch.conf file to work out what your system will use).#!/usr/local/bin/perl -w use Net::hostent; my @ips = qw( 1.2.3.4 5.6.7.8 ); # Use your own IPs my %hosts; foreach my $ip ( @ips ) { my $info = gethost( $ip ); # Returns an object unless( $info ) { warn( "gethost failed for [$ip] : $! $?" ); next; } # ...access other interesting bits of $info if you want... $hosts{$ip} = $info->name(); # Just want the name } # Ta da. The %hosts hash now contains a set of ip => host mappings. foreach my $ip ( keys %hosts ) { print "The hostname of IP address [$ip] is [$hosts{$ip}]\n"; }
|
|---|