Forum Moderators: coopster

Message Too Old, No Replies

PEAR Net_DNS

how to lookup an ip address

         

Draco Malfoy

11:23 pm on Aug 21, 2004 (gmt 0)

10+ Year Member



Is there any way to lookup an IP address from a hostname using a specified nameserver with PEAR Net_DNS? I downloaded Net_DNS but don't have a clue as to how to use it.

coopster

2:33 pm on Aug 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Draco Malfoy!

Will gethostbyname() [php.net] not work?

Draco Malfoy

6:26 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



You can't specify a nameserver with gethostbyname().

coopster

7:22 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yeah, I seen that in your first message, but figured I'd try anyway ;)

I found the *official* documentation when I clicked the author's name on the PEAR site and found a link to his home page. In his own words...


Documentation is still being written, although most of the major pieces are now complete. You can find my (poorly written) documentation at [ypass.net...]

coopster

9:40 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I happened to be installing PEAR on a server today. As I was loading stable packages, I came across the NET packages and caught this out of the corner of my eye...


Net_Dig [pear.php.net] class is no longer being maintained. Use of Net_DNS is recommended instead. A brief tutorial on how to migrate to Net_DNS is listed below.

I followed the link and found a step-by-step for you. I'll post the unlinked url and an example of how to use the code...

http://viebrock.ca/code/2/porting-netdig-to-netdns

<?php 
require 'Net/DNS.php';
$D = new Net_DNS();
$result = $D->resolver->query('example.com');
print_r($result);
?>

To check if the query was successful and, if so, to output the IP address:
<?php 
if ( $result->header->rcode!= 'NOERROR' && $result->header->ancount > 0 ) {
echo $result->answer[0]->address;
}
?>