Greetings!
I'm using the following code snippet to determine the DNS name associated with a particular IP address (Net::DNS::Resolver, Net::DNS::Packet and Net::DNS::RR are imported by the script):
my $l_dns = Net::DNS::Resolver->new( nameservers => qw(127.0.0.1) );
my $l_response = $l_dns->query($l_ip);
if($l_dns->errorstring eq 'NOERROR')
{
my $l_record;
foreach $l_record ($l_response->answer())
{
if($l_record->type() eq 'PTR')
{
$l_dns_name = $l_record->name();
last;
}
}
}
else
{
$l_dns_name = $l_ip;
}
Here $l_dns_name and $l_ip are defined elsewhere in the script and contain the (just determined) DNS name and the original IP address.
The only problem: It merely returns the IP address in .in-addr-arpa format instead of a domain name associated with it.
What could be going wrong here?
And to answer the obligatory question in advance: No, gethostbyname et al. is not what I want - I intend to directly access the local name server for name resolution.
Any help is greatly appreciated!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.