Skip to content

Instantly share code, notes, and snippets.

@pastranastevenaz
Created February 19, 2019 22:33
Show Gist options
  • Select an option

  • Save pastranastevenaz/c1b4cd60fabb1a15e2b95e189f47646f to your computer and use it in GitHub Desktop.

Select an option

Save pastranastevenaz/c1b4cd60fabb1a15e2b95e189f47646f to your computer and use it in GitHub Desktop.
Query the DNS of a domain passed to this function. Returns an array of all the DNS info, A, MX, TXT, and NS records
<?php
public function getdnsdata( $x ){
$aRecords = shell_exec("dig +short {$x} a");
$aArray = explode(PHP_EOL, $aRecords,1);
$mxRecords = shell_exec("dig +short {$x} mx");
$mxArray = explode(PHP_EOL, $mxRecords, -1);
$txtRecords = shell_exec("dig +short {$x} txt");
$txtArray = explode(PHP_EOL, $txtRecords, -1);
$nsRecords = shell_exec("dig +short {$x} ns");
$nsArray = explode(PHP_EOL, $nsRecords, -1);
return array(
"a" => str_replace("\n","",$aArray),
"mx" => $mxArray,
"txt" => preg_replace("/[^a-zA-Z0-9 \- \= \: \_ \. \~]/", "", $txtArray),
"ns" => $nsArray,
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment