Created
February 19, 2019 22:33
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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