Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolve hostname in PHP using different name server

Tags:

php

dns

nslookup

How I can resolve hostname to IP address using PHP, but using different nameserver (eg. OpenDNS or Google Public DNS).

It not seem that dns_get_record() or gethostbyname() are able to use a different nameserver than one currently set up on the system (in TCP/IP settings or in /etc/resolv.conf).

The only way I've found is using PEAR class Net/DNS, but it gives me lots of warnings under PHP 5.4

like image 638
Nick Avatar asked Jul 19 '12 15:07

Nick


People also ask

What is Dns_get_record?

The dns_get_record() function gets the DNS resource records associated with the specified hostname.

How do I find my hostname in PHP?

The gethostname() function returns the host name for the local machine.


1 Answers

<?
require_once 'Net/DNS2.php';

$resolver = new Net_DNS2_Resolver( array('nameservers' => array('208.67.222.123')) );

$resp = $resolver->query("hooktube.com.", 'A');

print_r($resp);

echo $resp->answer[0]->address;
like image 104
Nick Avatar answered Sep 22 '22 23:09

Nick