blake in
<[EMAIL PROTECTED]>:

> I am new to perl and attempting to write a script that will do a reverse dns
> lookup on an ip [snip]

Just looking that far, I don't think your script will work as you
intend. Here's a ptr lookup using dig ... 

| dig -x 217.151.101.100
| 100.101.151.217.in-addr.arpa. 86162 IN  CNAME   
100.96/29.101.151.217.in-addr.arpa.
| 100.96/29.101.151.217.in-addr.arpa. 172800 IN PTR mail.rdns.org.

As you can see, it returns two answer records, one a cname and
the other a ptr. Whether that happens depends on how the dns
reverse tree is delegated (by the isp). 

Running the relevant portions of your script on the above ip
address and adding the following line ...

| print "type returned: ",$r -> type,"\n";

... produces the following output ...

| perl try-rdns.pl 217.151.101.100
| type returned: CNAME
| Error: query returned result other than PTR record at try-rdns.pl line 34.

... whereas, of course, there is a valid ptr-record associated
with that ip address.

This is how I lookup ptr-records ... 

| use Net::DNS::Resolver;
| use strict;
| use warnings;
| 
| # comma separated list of name servers
| my $resolvers = '217.151.101.101';
| 
| my $res = Net::DNS::Resolver -> new(
|     nameservers => [$resolvers],
|         recurse => 1,
|           debug => 0,
| );
| 
| my $ip = '217.151.101.100';
| 
| my @returns = ptr_lookup($ip);
| print $ip, "\n", join "\n", @returns;
| 
| sub ptr_lookup {
|     my $ip = shift;
|     my @data;
|     my $query = $res -> send($ip, "PTR");
|     if ($query) {
|         foreach my $rr ($query -> answer) {
|             next unless $rr -> type eq "PTR";
|             push @data, $rr -> ptrdname;
|     }
|     push @data, $res -> errorstring unless @data;
|     return @data;
| }

Another possible problem is that there can be multiple
ptr-records assigned to a single ip address, each of them equally
valid and returned in no special order (ie it doesn't make any
sense to choose the first in preference to the last when
displaying lookup results). Here's a typical example of what
you'll see from some web-hosting providers ... 

| dig -x 82.197.74.12
| 12.74.197.82.in-addr.arpa. 3600 IN      PTR     hotfix.lynxinternet.com.
| 12.74.197.82.in-addr.arpa. 3600 IN      PTR     christy.lynxinternet.com.
| 12.74.197.82.in-addr.arpa. 3600 IN      PTR     christest7.lynxinternet.co.uk.
| 12.74.197.82.in-addr.arpa. 3600 IN      PTR     whatadeal.co.uk.
| 12.74.197.82.in-addr.arpa. 3600 IN      PTR     christest8.lynxinternet.co.uk.
| 12.74.197.82.in-addr.arpa. 3600 IN      PTR     christest9.lynxinternet.co.uk.
| 12.74.197.82.in-addr.arpa. 3600 IN      PTR     www.whatadeal.co.uk.
| 12.74.197.82.in-addr.arpa. 3600 IN      PTR     
laptopexpress.lynxinternet.com.
| 12.74.197.82.in-addr.arpa. 3600 IN      PTR     www.cstecommerce.co.uk.
| 12.74.197.82.in-addr.arpa. 3600 IN      PTR     soldpropertyprices.co.uk.
| 12.74.197.82.in-addr.arpa. 3600 IN      PTR     www.soldpropertyprices.co.uk.
| 12.74.197.82.in-addr.arpa. 3600 IN      PTR     www.edt-fragrances.co.uk.
| 12.74.197.82.in-addr.arpa. 3600 IN      PTR     edt-fragrances.co.uk.
| 12.74.197.82.in-addr.arpa. 3600 IN      PTR     
christest10.lynxinternet.co.uk.
| 12.74.197.82.in-addr.arpa. 3600 IN      PTR     test.lynxinternet.com.

How you factor that into your application is up to you.
-- 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to