brianjb has asked for the wisdom of the Perl Monks concerning the following question:
This is the output you get when you run it:#!/usr/bin/perl use strict; use warnings; use Net::DNS::Resolver; my $hostname = 'perlmonks.org'; my $res = Net::DNS::Resolver->new( nameservers => [qw(8.8.8.8)], ); my $query = $res->search($hostname); if ($query) { foreach my $rr ($query->answer) { next unless $rr->type eq "A"; print "Found an A record for $hostname: ".$rr->address; print "\n"; } }
So now taking it a step further, I want to check a whole file of names. This is the code I have, but it's not working. Can someone please help and let me know where I went wrong?Found an A record for perlmonks.org: 66.39.54.27 Found an A record for perlmonks.org: 216.92.34.251 Found an A record for perlmonks.org: 209.197.123.153
#!/usr/bin/perl use strict; use warnings; use Net::DNS::Resolver; open FILE, "<hostname_check.txt" || die $!; while (<FILE>) { my $res = Net::DNS::Resolver->new( nameservers => [qw(8.8.8.8)], ); my $query = $res->search($_); if ($query) { foreach my $rr ($query->answer) { next unless $rr->type eq "A"; print "Found an A record for $_: ".$rr->address; print "\n"; } } } close FILE;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need help with script with a while loop reading file
by hdb (Monsignor) on May 03, 2013 at 13:56 UTC | |
by brianjb (Novice) on May 03, 2013 at 14:26 UTC | |
|
Re: Need help with script with a while loop reading file
by blue_cowdawg (Monsignor) on May 03, 2013 at 13:57 UTC | |
by brianjb (Novice) on May 03, 2013 at 14:34 UTC | |
|
Re: Need help with script with a while loop reading file
by 2teez (Vicar) on May 03, 2013 at 16:23 UTC | |
|
Re: Need help with script with a while loop reading file
by NetWallah (Canon) on May 03, 2013 at 14:54 UTC |