Skip to content

Instantly share code, notes, and snippets.

@lantins
Created September 1, 2014 22:39
Show Gist options
  • Save lantins/ec5d9fdbf095a2810d88 to your computer and use it in GitHub Desktop.
Save lantins/ec5d9fdbf095a2810d88 to your computer and use it in GitHub Desktop.
Get DNS servers from root servers using dig (hack)
<?php
function get_ns_from_root($hostname) {
$regex_hostname = preg_quote($hostname);
$dig_cmd = "dig +trace {$hostname} | egrep '^{$regex_hostname}\..*IN.*NS' | awk '{ print $5 }'";
exec($dig_cmd, $nameservers);
return $nameservers;
}
$hostname = 'buycity.info';
$nameservers = get_ns_from_root($hostname)l
print_r($nameservers);
# Output:
#
# Array
# (
# [0] => ns4.hosteceran.com.
# [1] => ns2.hosteceran.com.
# [3] => ns3.hosteceran.com.
# [2] => ns1.hosteceran.com.
# )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment