tclserv

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

dnslib.php (1487B)


      1 <?php
      2 
      3 # Following function is jaffacake's own work.
      4 # GPLv3 blablabla
      5 
      6 define("DNSBL",0x1);
      7 define("NORMLOOKUP",0x2);
      8 define("V6LOOKUP",0x4);
      9 define("REVLOOKUP",0x8);
     10 
     11 function dig($name, $qtype, $dnsbl = ".", $isdnsbl = false) {
     12 	$type = 0;
     13 	if ($isdnsbl >= 1) {
     14 		$isipv6 = (strpos($name, ":") !== FALSE);
     15 		if ($dnsbl == ".") return false;
     16 		if ($isipv6) {
     17 			$type = $type | V6LOOKUP;
     18 		}
     19 		$type = $type | DNSBL;
     20 		$type = $type | REVLOOKUP;
     21 	}
     22 	if (!$isdnsbl) $type = NORMLOOKUP;
     23 	if ($qtype == "PTR") {
     24 		$isipv6 = (strpos($name, ":") !== FALSE);
     25 		if ($isipv6) {
     26 			$type = $type | REVLOOKUP;
     27 		}
     28 		$type = $type | REVLOOKUP;
     29 	}
     30 	if ($type & 0x8) {
     31 		if ($type & V6LOOKUP) $rdns = implode(".",str_split(strrev(implode("",explode(":",$name)))));
     32 		else $rdns = implode(".",array_reverse(explode(".",$name)));
     33 		$dname = $rdns;
     34 		if (($type & 0x4) and ($type & 0x1)) $dname .= ".ip6.arpa";
     35 		else if ($type & 0x2) $dname .= ".in-addr.arpa";
     36 		else {
     37 			$dname .= ".".$dnsbl;
     38 		}
     39 	} else $dname = $name;
     40 	$dnsname = "dig +short +time=1 ".escapeshellarg($dname)." ".escapeshellarg(strtoupper($qtype))." | tail -n 1";
     41 	$out = shell_exec($dnsname);
     42 	if ($type & 0x1) {
     43 		$num = explode(".",$out);
     44 		$numreply = 0;
     45 		$numreply = $numreply + $num[3];
     46 		$numreply = $numreply + ($num[2] << 8);
     47 		$numreply = $numreply + ($num[1] << 16);
     48 		// We'll return the pton result :P
     49 		return $numreply;
     50 	}
     51 	return $out;
     52 }
     53 
     54 print($argv[5]. " " .dig($argv[1], $argv[2], $argv[3], $argv[4]). "\n");