Advertisement
Guest User

Pear Net DNS2 lookup many record types and sub-domains

a guest
Oct 25th, 2015
830
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.54 KB | None | 0 0
  1. <?php
  2. if($_GET['showData']){
  3.         echo "Posted: <pre>";
  4.         print_r($_GET);
  5.         echo "</pre>\n";
  6. }
  7.  
  8. $host = trim($_GET['host']);
  9. require_once 'Net/DNS2.php';
  10.  
  11. switch($_GET['ns']){
  12.         case "google":
  13.                 $ns = array('8.8.8.8');
  14.                 break;
  15.         default:
  16.                 if(isset($_GET['other'])){
  17.                         $ns = array($_GET['other']);
  18.                 } else {
  19.                         $ns = array($_GET['ns']);
  20.                 }
  21.                 break;
  22. }
  23.  
  24. if(isset($_GET['supNoData'])){
  25.         $suppressNoData = true;
  26. } else {
  27.         $suppressNoData = false;
  28. }
  29.  
  30. $r = new Net_DNS2_Resolver(array(
  31.         'nameservers' => $ns
  32. ));
  33. if(empty($_GET['r'])){
  34.         // Set Default Record Types to lookup
  35.         $_GET['r'] = array('A', 'MX', 'SRV', 'TXT', 'CNAME', 'NS');
  36. }
  37.  
  38. if(empty($_GET['s'])){
  39.         // Set Default Dub-Domains to lookup
  40.         $_GET['s']['a'] = array('root', 'ftp', 'list', 'mail', 'store', 'www');
  41.         $_GET['s']['m'] = array('list');
  42.         $_GET['s']['c'] = array('autodiscover');
  43.         $_GET['s']['s'] = array('_sip._tls', '_sipfederationtls._tcp');
  44. }
  45.  
  46. if($_GET['showData']){
  47.         echo "After Default adds: <pre>";
  48.         print_r($_GET);
  49.         echo "</pre>\n";
  50. }
  51. echo "<table>\n";
  52. echo "\t<tr><th>domain</th><th>type</th><th>data</th><th>ttl</th></tr>\n";
  53.  
  54. $record_results = array();
  55.  
  56. foreach($_GET['r'] as $record){
  57.         // A Records
  58.         if($record == "A"){
  59.                 if($_GET['s']['a'][0] == "root"){
  60.                         if($_GET['showData']){
  61.                                 echo "<tr><td colspan='4'>Performing A Record lookup on $host</td></tr>\r\n";
  62.                         }
  63.                         try {
  64.                                 $result = $r->query($host, 'A');
  65.                         } catch(Net_DNS2_Exception $e) {
  66.                                 //echo "::query() failed: ", $e->getMessage(), "\n";
  67.                                 if(!$suppressNoData){
  68.                                         printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>\n", $host, "A", "No Data", 0);
  69.                                 }
  70.                                 continue;
  71.                         }
  72.  
  73.                         //
  74.                         // loop through the answer, printing out the A records returned.
  75.                         //
  76.                         foreach($result->answer as $arr) {
  77.                                 $data = $arr->address;
  78.                                 printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>\n", $arr->name, $arr->type, $data, $arr->ttl);
  79.                                 $record_results[] = array(
  80.                                         'domain' => $arr->name,
  81.                                         'type' => $arr->type,
  82.                                         'data' => $arr->address,
  83.                                         'ttl' => $arr->ttl
  84.                                 );
  85.                         }
  86.                         unset($_GET['s']['a'][0]);
  87.                 }
  88.                 if(isset($_GET['s']['a'])){
  89.                         foreach($_GET['s']['a'] as $sub){
  90.                                 if($_GET['showData']){
  91.                                         echo "<tr><td colspan='4'>Performing A Record lookup on $sub.$host</td></tr>\r\n";
  92.                                 }
  93.                                 try {
  94.                                         $lookup = "$sub.$host";
  95.                                         $result = $r->query($lookup, 'A');
  96.                                 } catch(Net_DNS2_Exception $e) {
  97.                                         //echo "::query() failed: ", $e->getMessage(), "\n";
  98.                                         if(!$suppressNoData){
  99.                                                 printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>\n", "$sub.$host", "A", "No Data", 0);
  100.                                         }
  101.                                         continue;
  102.                                 }
  103.  
  104.                                 //
  105.                                 // loop through the answer, printing out the A records returned.
  106.                                 //
  107.                                 foreach($result->answer as $a2rr) {
  108.                                         $data = $a2rr->address;
  109.                                         printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>\n", $a2rr->name, $a2rr->type, $data, $a2rr->ttl);
  110.                                         $record_results[] = array(
  111.                                                 'domain' => $a2rr->name,
  112.                                                 'type' => $a2rr->type,
  113.                                                 'data' => $a2rr->address,
  114.                                                 'ttl' => $a2rr->ttl
  115.                                         );
  116.                                 }
  117.                         }
  118.                 }
  119.         }
  120.         // MX Records
  121.         if($record == "MX"){
  122.                 if($showData){
  123.                         echo "<tr><td colspan='4'>Performing MX Record lookup on $host</td></tr>\r\n";
  124.                 }
  125.                 try {
  126.                         $result = $r->query($host, 'MX');
  127.                 } catch(Net_DNS2_Exception $e) {
  128.                         //echo "::query() failed: ", $e->getMessage(), "\n";
  129.                         if(!$suppressNoData){
  130.                                 printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>\n", $host, "MX", "0 No Data", 0);
  131.                         }
  132.                         continue;
  133.                 }
  134.  
  135.                 //
  136.                 // loop through the answer, printing out the MX servers returned.
  137.                 //
  138.                 foreach($result->answer as $mxrr){
  139.                         printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>\n", $mxrr->name, $mxrr->type, $mxrr->preference . " " . $mxrr->excha$
  140.                         $record_results[] = array(
  141.                                 'domain' => $mxrr->name,
  142.                                 'type' => $mxrr->type,
  143.                                 'data' => $mxrr->preference . " " . $mxrr->exchange,
  144.                                 'ttl' => $mxrr->ttl
  145.                         );
  146.                 }
  147.                 foreach($result->answer as $mxrr){
  148.                         printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>\n", $mxrr->name, $mxrr->type, $mxrr->preference . " " . $mxrr->excha$
  149.                         $record_results[] = array(
  150.                                 'domain' => $mxrr->name,
  151.                                 'type' => $mxrr->type,
  152.                                 'data' => $mxrr->preference . " " . $mxrr->exchange,
  153.                                 'ttl' => $mxrr->ttl
  154.                         );
  155.                 }
  156.                 if(isset($_GET['s']['m'])){
  157.                         foreach($_GET['s']['m'] as $sub){
  158.                                 try {
  159.                                         $result = $r->query("$sub.$host", 'MX');
  160.                                 } catch(Net_DNS2_Exception $e) {
  161.                                         //echo "::query() failed: ", $e->getMessage(), "\n";
  162.                                         if(!$suppressNoData){
  163.                                                 printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>\n", "0 $sub.$host", "MX", "No Data", 0);
  164.                                         }
  165.                                         continue;
  166.                                 }
  167.                                 foreach($result->answer as $mxrr){
  168.                                         printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>\n", $mxrr->name, $mxrr->type, $mxrr->preference . " $
  169.                                        $record_results[] = array(
  170.                                                'domain' => $mxrr->name,
  171.                                                'type' => $mxrr->type,
  172.                                                'data' => $mxrr->preference . " " . $mxrr->exchange,
  173.                                                'ttl' => $mxrr->ttl
  174.                                        );
  175.                                }
  176.                        }
  177.                }
  178.        }
  179.        // Text Record
  180.        if($record == "TXT"){
  181.                if($showData){
  182.                        echo "<tr><td colspan='4'>Performing TXT Record lookup on $host</td></tr>\r\n";
  183.                }
  184.                try {
  185.                        $result = $r->query($host, 'TXT');
  186.                } catch(Net_DNS2_Exception $e) {
  187.                        //echo "::query() failed: ", $e->getMessage(), "\n";
  188.                        if(!$suppressNoData){
  189.                                printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>\n", $host, "TXT", "No Data", 0);
  190.                        }
  191.                        continue;
  192.                }
  193.  
  194.                //
  195.                // loop through the answer, printing out the TXT servers returned.
  196.                //
  197.               foreach($result->answer as $txtrr){
  198.                        if($txtrr->text[0] == "" || $txtrr->text[0] == " "){ continue; }
  199.                        printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>\n", $txtrr->name, $txtrr->type, $txtrr->text[0], $txtrr->ttl);
  200.                        $record_results[] = array(
  201.                                'domain' => $txtrr->name,
  202.                                'type' => $txtrr->type,
  203.                                'data' => $txtrr->text[0],
  204.                                'ttl' => $txtrr->ttl
  205.                        );
  206.                }
  207.        }
  208.        // SRV Records
  209.        if($record == "SRV"){
  210.                if(isset($_GET['s']['s'])){
  211.                        foreach($_GET['s']['s'] as $sub){
  212.                                if($showData){
  213.                                        echo "<tr><td colspan='4'>Performing SRV Record lookup on $sub.$host</td></tr>\r\n";
  214.                                }
  215.                                try {
  216.                                        $result = $r->query("$sub.$host", 'SRV');
  217.                                } catch(Net_DNS2_Exception $e) {
  218.                                        //echo "::query() failed: ", $e->getMessage(), "\n";
  219.                                        if(!$suppressNoData){
  220.                                                printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>\n", "$sub.$host", "SRV", "0 0 0 No Data", 0);
  221.                                        }
  222.                                        continue;
  223.                                }
  224.  
  225.                                //
  226.                                // loop through the answer, printing out the SRV servers returned.
  227.                                //
  228.                                foreach($result->answer as $srvrr) {
  229.                                        printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>\n", $srvrr->name, $srvrr->type, $srvrr->priority . "$
  230.                                         $record_results[] = array(
  231.                                                 'domain' => $srvrr->name,
  232.                                                 'type' => $srvrr->type,
  233.                                                 'data' => $srvrr->priority . " " . $srvrr->weight . " " . $srvrr->port . " " . $srvrr->target,
  234.                                                 'ttl' => $srvrr->ttl
  235.                                         );
  236.                                 }
  237.                         }
  238.                 }
  239.         }
  240.         // CNAME Records
  241.         if($record == "CNAME"){
  242.                 if(isset($_GET['s']['c'])){
  243.                         foreach($_GET['s']['c'] as $sub){
  244.                                 if($showData){
  245.                                         echo "<tr><td colspan='4'>Performing CNAME Record lookup on $sub.$host</td></tr>\r\n";
  246.                                 }
  247.                                 try {
  248.                                         $result = $r->query("$sub.$host", "CNAME");
  249.                                 } catch(Net_DNS2_Exception $e) {
  250.                                         //echo "::query() failed: ", $e->getMessage(), "\n";
  251.                                         if(!$suppressNoData){
  252.                                                 printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>\n", "$sub.$host", "CNAME", "No Data", 0);
  253.                                         }
  254.                                         continue;
  255.                                 }
  256.  
  257.                                 foreach($result->answer as $crr) {
  258.                                         printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>\n", $crr->name, $crr->type, $crr->cname, $crr->ttl);
  259.                                         $record_results[] = array(
  260.                                                 'domain' => $crr->name,
  261.                                                 'type' => $crr->type,
  262.                                                 'data' => $crr->cname,
  263.                                                 'ttl' => $crr->ttl
  264.                                         );
  265.                                 }
  266.                         }
  267.                 }
  268.         }
  269.         // Name Server Records
  270.         if($record == "NS"){
  271.                 if($showData){
  272.                         echo "<tr><td colspan='4'>Performing NS Record lookup on $host</td></tr>\r\n";
  273.                 }
  274.                 try {
  275.                         $result = $r->query("$host", "NS");
  276.                 } catch(Net_DNS2_Exception $e) {
  277.                         //echo "::query() failed: ", $e->getMessage(), "\n";
  278.                         if(!$suppressNoData){
  279.                                 printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>\n", $host, "NS", "No Data", 0);
  280.                         }
  281.                         continue;
  282.                 }
  283.                 foreach($result->answer as $nsrr) {
  284.                         printf("\t<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td></tr>\n", $nsrr->name, $nsrr->type, $nsrr->nsdname, $nsrr->ttl);
  285.                         $record_results[] = array(
  286.                                 'domain' => $nsrr->name,
  287.                                 'type' => $nsrr->type,
  288.                                 'data' => $nsrr->nsdname,
  289.                                 'ttl' => $nsrr->ttl
  290.                         );
  291.                 }
  292.         }
  293. }
  294. echo "</table>\n";
  295. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement