Question

I am trying to retrieve the name servers of a given domain, preferably in PHP.

I've tried a number of approaches but am unable to get any decent/consistent results and was wondering if anyone knew of a function or class that might help me achieve this?

For example, this whois class has some success, but fails to retireve the name server from dot com TLDs.

I was thinking that I could perhaps use Google's DNS server 8.8.8.8 in some way perhaps, but am unsure how?

Any pointers would be much appreciated.

Était-ce utile?

La solution

The answer is this function:

http://www.php.net/manual/en/function.dns-get-record.php

$result = dns_get_record("stackoverflow.com");
var_dump($result);

Autres conseils

See this.

For PHP On Windows:

$e = 'nslookup -debug www.google.com. 8.8.8.8';

For PHP On Mac and Linux:

$e = 'dig @8.8.8.8 www.google.com.';

And then,

$o = array();
$r = -1;
$ip = exec($e,$o,$r);
if($r == 0) // success
{
    // do some regexp or explosion depending upon your output format to get the ip
    // here is for windows:
    $ip = trim(explode("Address:", $ip)[1]);
}

There are some PHP functions to do that.

http://www.php.net/manual/en/function.gethostbyname.php http://php.net/manual/en/function.gethostbyaddr.php

perhaps you can use that.

Edit: On the left you have a complete list for Network functions.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top