Get details about DNS lookup of the domains with php.This simple php script can be used to get details about DNS lookup with MX records,text records,CNAME records,SOA…etc . Final result is getting 2D or 3D array of the DNS lookup details of the given domain.
1 2 3 4 |
$domainName = 'google.com'; $rec = dns_get_record($domainName, DNS_ALL); // get all records print_r($rec); |
Final output
Array
(
[0] => Array
(
[host] => webexplorar.com
[type] => MX
[pri] => 1
[target] => ASPMX.L.GOOGLE.com
[class] => IN
[ttl] => 14400
)
[1] => Array
(
[host] => webexplorar.com
[type] => MX
[pri] => 5
[target] => ALT1.ASPMX.L.GOOGLE.com
[class] => IN
[ttl] => 14400
)
[2] => Array
(
[host] => webexplorar.com
[type] => MX
[pri] => 5
[target] => ALT2.ASPMX.L.GOOGLE.com
[class] => IN
[ttl] => 14400
)
[3] => Array
(
[host] => webexplorar.com
[type] => MX
[pri] => 10
[target] => ASPMX2.GOOGLEMAIL.com
[class] => IN
[ttl] => 14400
)
[4] => Array
(
[host] => webexplorar.com
[type] => MX
[pri] => 10
[target] => ASPMX3.GOOGLEMAIL.com
[class] => IN
[ttl] => 14400
)
[5] => Array
(
[host] => webexplorar.com
[type] => TXT
[txt] => v=spf1 +a +mx +ip4:204.152.255.8 ?all
[entries] => Array
(
[0] => v=spf1 +a +mx +ip4:204.152.255.8 ?all
)
[class] => IN
[ttl] => 14400
)
[6] => Array
(
[host] => webexplorar.com
[type] => SOA
[mname] => ns1.hostable.com
[rname] => noc.brinkster.com
[serial] => 2013012101
[refresh] => 86400
[retry] => 7200
[expire] => 3600000
[minimum-ttl] => 86400
[class] => IN
[ttl] => 86400
)
If you want to display DNS lookup details as formatted table, do that as following.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$details =''; $data = '<table width="500" cellpadding="1" cellspacing="1" border="0" class="dnsDetailsTable">'; foreach ($rec as $arr => $num){ $details .='<tr>'; foreach ($num as $title => $value){ if(!is_array($value)){ $details .='<td>'.$value.'</td>'; } } $details .='</tr>'; } $data .=$details.'</table>'; echo '<pre>'.$data.' |
’;
Final output after formatted
webexplorar.com MX 10 ASPMX3.GOOGLEMAIL.com IN 14400
webexplorar.com MX 1 ASPMX.L.GOOGLE.com IN 14400
webexplorar.com MX 5 ALT1.ASPMX.L.GOOGLE.com IN 14400
webexplorar.com MX 5 ALT2.ASPMX.L.GOOGLE.com IN 14400
webexplorar.com MX 10 ASPMX2.GOOGLEMAIL.com IN 14400
webexplorar.com TXT v=spf1 +a +mx +ip4:204.152.255.8 ?all IN 14400
webexplorar.com SOA ns1.hostable.com noc.brinkster.com 2013012101 86400 7200 3600000 86400 IN 86400
webexplorar.com NS ns1.hostable.com IN 86400
webexplorar.com NS ns2.hostable.com IN 86400
webexplorar.com A 204.152.255.8 IN 14400