class DigIt {
function loadFormat() {
$f["server_found"][] = "/; \((.*) server found\)/";
$f["next_update"][] = "/;; ANSWER SECTION:\n".$this->domain.". (.*) IN/";
#$f["next_update"][] = 1;
$f["ip"][] = "/(.*)IN A (.*)/";
$f["ip"][] = 2;
$f["query_time"][] = "/;; Query time: (.*) msec/";
$f["dns_ip"][] = "/;; SERVER: (.*)#/";
$this->format = $f;
}
function getDig() {
if($this->dns)
$dns = "@".$this->dns;
if($this->type)
$type= $this->type;
$cmd = "dig $dns '".$this->domain."' $type ";
$this->ShRes = shell_exec($cmd);
#echo "".$this->ShRes."
";
}
function setFormat() {
$analyse = 0;
$t = $this->ShRes;
foreach($this->format as $k => $v) {
preg_match_all($v[0],$t,$o);
# if($k=="next_update") $this->print_rf($o);
if($v[1]) $at[$k] = $o[$v[1]][0];
else $at[$k] = $o[1][0];
}
#exit;
$this->FoRes = $at;
}
function formatTime($s) {
$h = floor($s/3600);
$s -= $h*3600;
$m = floor($s/60);
$s -= $m*60;
if($h > 0) $text = sprintf("%d h %d min %d sec",$h,$m,$s);
elseif($m > 0) $text = sprintf("%d min %d sec",$m,$s);
else $text = sprintf("%d sec",$s);
return $text;
}
function print_rf($a) {
echo "";
print_r($a);
echo "
";
}
function getResult() {
$this->getDig();
$this->loadFormat();
$this->setFormat();
return $this->FoRes;
}
}