Get access to free VOIP training. Sign up below.



Web based dig using PHP

Here is something a little different. I attempted to make a very basic web based utility.

The front page utilizes a JavaScript framework from  http://www.prototypejs.org/ by Sam Stephenson to perform from AJAX magic.

Next is a very basic PHP script that executes the dig command from the local server. All of the output from the dig is placed into an array and then printed to the screen.

<-- Begin dig.html -->

<html>
<head>
<script type="text/javascript" src="xajax_core.js"></script>
<script>

function Dig() {
new Ajax.Request("webdig2.php",
{
method: 'post',
postBody: 'T1='+ $F('GetDomain') +'&dropdown='+ $F('options'),

onComplete: ShowDig
});
}

function ShowDig(req){
$('show').innerHTML= req.responseText;
}

</script>
<style type="text/css">
body {
color: green;
background-color: white;
font-size: medium; }
</style>

</head>

<body>

<b>Please enter the domain name. For PTR (Reverse DNS) you must enter the IP address.</b>
<br>
<br>

<form id ="Dig" onsubmit="return false;">
Domain / IP <input type="text" Name="domain" id="GetDomain" />
<select name="dropdown" value="options" id="options">
<option value="ARec">A Record</option>
<option value="CNAME">CNAME Record</option>
<option value="MX">MX Record</option>
<option value="SRV">SRV Record</option>
<option value="PTR">PTR / Reverse DNS</option>
</select>

<input type="submit" value="lookup" onClick="Dig()">

</form>
<br />
<br />
<br />
<br />

<div id="show"> </div>
</body>

</html>

<-- End Dig.html-->>

<-- Begin webdig2.php -->
<?php

import_request_variables('p', 'p_');

function print_r_html ($arr) {
?><pre><?
print_r($arr);
?></pre><?
}

// Define Variables from the form.
$VAR1 = "$p_T1";
$VAR3 = "$p_dropdown";

function ARECORD() {
global $VAR1;
exec("dig $VAR1 A ", $OUT);
for ( $i=0; $i < count($OUT); $i++) {
print_r_html ($OUT[$i]) ;
}
exit;
}

function CNAMERECORD(){
global $VAR1;
exec("dig $VAR1 CNAME ", $OUT);
for ( $i=0; $i < count($OUT); $i++) {
print_r_html ($OUT[$i]) ;
}

exit;
}

function MXRECORD(){
global $VAR1;
exec("dig $VAR1 MX ", $OUT);
for ( $i=0; $i < count($OUT); $i++) {
print_r_html ($OUT[$i]) ;
}

exit;
}

function SRVRECORD(){
global $VAR1;
exec("dig $VAR1 SRV ", $OUT);
for ( $i=0; $i < count($OUT); $i++) {
print_r_html ($OUT[$i]) ;
}

exit;
}

function PTRECORD(){
global $VAR1;
exec("dig -x $VAR1 ", $OUT);
for ( $i=0; $i < count($OUT); $i++) {
print_r_html ($OUT[$i]) ;
}

exit;
}

if ( $VAR3 == "ARec" ) ARECORD ();
if ( $VAR3 == "CNAME" ) CNAMERECORD ();
if ( $VAR3 == "MX" ) MXRECORD ();
if ( $VAR3 == "SRV" ) SRVRECORD ();
if ( $VAR3 == "PTR" ) PTRECORD ();
else;
exit;

?>

<-- End webdig2.php -->

One thought on “Web based dig using PHP

Comments are closed.