function DoTest($testname, $param, $hostname, $timeout, $params) { $timer = new TFNTimer(); if ($param == "") { $dnsserver = $hostname; } else { $dnsserver = $param; } if ($dnsserver == "") { return -3; } if ($timeout <= 0) { $timeout = 60; } if ($params[4] == 1) { $udp = false; } else { $udp = true; } if ($params[3] == "" || $params[3] == 0) { $port = 53; } else { $port = $params[3]; } $dns_query = new DNSQuery($dnsserver, $port, $timeout, $udp, false); // run with debug off $type = $params[2]; $query = $params[1]; $timer->Start(); $answer = $dns_query->Query($query, $type); $elapsedTime = $timer->Stop(); if ($answer === false || $dns_query->error) { return -2; } // query error if ($answer->count <= 0) { return -1; } // no records returned // otherwise we've got some results ok $elapsedTime = round($elapsedTime, 4); if ($elapsedTime <= 0) { return 0.0001; } return $elapsedTime; break; }
function DoTest($testname, $param, $hostname, $timeout, $params) { $timer = new TFNTimer(); // First initialise DNS query object $dnsserver = $params[1]; if ($dnsserver == "") { return -3; } $dnsserver = ip_lookup($dnsserver); $url = $param; $dns_delay = $params[2]; if ($dns_delay == 0 || !is_numeric($dns_delay)) { $dns_delay = 0; } // default no extra delay if ($timeout <= 0) { $timeout = 60; } $udp = true; // initial setting $port = 53; $dns_query = new DNSQuery($dnsserver, $port, $timeout, $udp, false); // run with debug off $type = "A"; $matches = ""; $out = preg_match("@^(?:http[s]*://)?([^/|\\?|:]+)@i", $url, $matches); $hostname = $matches[1]; // strip out hostname for FQDN lookup $host_no_dots = str_replace(".", "", $hostname); if (is_numeric($host_no_dots)) { $is_ip_address = true; } else { $is_ip_address = false; } $timer->Start(); if (!$is_ip_address) { $answer = $dns_query->Query($hostname, $type); //echo "DNS"; if ($answer === false || $dns_query->error) { $udp = false; // switch to TCP $dns_query->udp = $udp; // wait! while ($timer->Stop() < $dns_delay) { usleep(100); } $answer = $dns_query->Query($hostname, $type); //echo "DNS2"; } if ($answer->count <= 0) { return -1; } // no records returned if ($answer === false) { return -1; } // object is false if ($dns_query->error) { return -1; } // DNS object error $dns_time_taken = $timer->Stop(); // if we get this far the DNS has worked $ip_address = url_lookup($url); // pre-cache DNS } else { $dns_time_taken = 0; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_MAXREDIRS, 32); if ($timeout > 0) { curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); } if ($timeout > 0) { curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); } // restart timer $timer->Start(); if (!($output = curl_exec($ch))) { $ctr = -1; // failed } else { $ctr = round(curl_getinfo($ch, CURLINFO_SIZE_DOWNLOAD) / 1024, 2); } $fetch_time_taken = $timer->Stop(); curl_close($ch); if ($ctr <= 0) { return -2; } // URL request failed return $dns_time_taken + $fetch_time_taken; // return elapsed time taken }
?> > <table class="form-table no-margin"> <?php if ($dkim && mymail_option('dkim_private_key') && mymail_option('dkim_public_key')) { ?> <tr valign="top"> <th scope="row"> </th> <td> <?php $pubkey = trim(str_replace(array('-----BEGIN PUBLIC KEY-----', '-----END PUBLIC KEY-----', "\n", "\r"), '', mymail_option('dkim_public_key'))); $record = 'k=rsa;t=y;' . "\n" . 'p=' . $pubkey; $host = mymail_option('dkim_selector') . '._domainkey.' . mymail_option('dkim_domain'); if (false === ($records = get_transient('mymail_dkim_records'))) { require_once MYMAIL_DIR . '/classes/libs/dns.class.php'; $dns_query = new DNSQuery('8.8.8.8'); $result = $dns_query->Query($host, 'TXT'); if ($result->count) { $records = json_decode(json_encode($result->results), true); set_transient('mymail_dkim_records', $records, 900); } } $found = false; if ($records) { foreach ($records as $r) { if ($r['typeid'] === 'TXT' && preg_replace('#[^a-zA-Z0-9]#', '', $r['data']) == preg_replace('#[^a-zA-Z0-9]#', '', $record)) { $found = $r; break; } } }
$s = ""; } echo "<input type=checkbox name=binarydebug value=1" . $s . "> Binary Debug<br>"; if ($extendanswer) { $s = " checked"; } else { $s = ""; } echo "<input type=checkbox name=extendanswer value=1" . $s . "> Show Detail<br>"; echo "</td></tr><tr><td> </td><td>"; echo "<input type=submit value=\"Perform DNS Query\"><br>"; echo "</td></tr></table>"; // ** HERE IS THE QUERY SECTION ** // if (isset($_REQUEST['doquery'])) { echo "<pre>"; $query = new DNSQuery($server, $port, $timeout, $udp, $debug); if ($binarydebug) { $query->binarydebug = true; } if ($type == "SMARTA") { echo "Smart A Lookup for " . $question . "\n\n"; $hostname = $query->SmartALookup($question); echo "Result: " . $hostname . "\n\n"; echo "</pre>"; Screen_Footer(); exit; } echo "Querying: " . $question . " -t " . $type . " @" . $server . "\n"; $result = $query->Query($question, $type); if ($query->error) { echo "\nQuery Error: " . $query->lasterror . "\n\n";