Beispiel #1
0
/**
 * Retrieve all DNS records for a given host, with 5 seconds as the default
 * timeout for the operation, using Google's public nameservers.
 */
function resolv_get_records($host, $query = DNS_ALL, $timeout = 5.0, $ns = null)
{
    if (is_null($query)) {
        $query = DNS_ALL;
    }
    $query = _resolv_convert_query($query);
    if (is_null($ns)) {
        $ns = '8.8.8.8';
    }
    try {
        $start = microtime(true);
        $res = _resolv_choice([function () use($host, $query, &$timeout, $ns) {
            return call_user_func_array("_resolv_query_udp", [$host, $timeout, $ns, $query]);
        }, function () use($start, &$timeout) {
            $timeout -= microtime(true) - $start;
            return [false, null];
        }, function () use($host, $query, &$timeout, $ns) {
            return call_user_func_array("_resolv_query_tcp", [$host, $query, $ns, $query]);
        }]);
        if (is_null($res)) {
            throw new Exception("Unable to fetch records");
        }
        // Handle response
        if ($res->getResponseCode() !== 0) {
            throw new Exception("Server returned error code " . $res->getResponseCode());
        }
        return _resolv_convert_results($res, $host);
    } catch (Exception $e) {
        return [];
    }
}
Beispiel #2
0
if (sizeof(array_diff($native, $resolv)) || sizeof(array_diff($resolv, $native))) {
    echo "Failed check for bcc.com A records\n";
    var_dump($native);
    var_dump($resolv);
    exit(1);
}
$native = array_map("_target", dns_get_record("bbc.com", DNS_MX));
$resolv = array_map("_target", resolv_get_records("bbc.com", DNS_MX, 5, "8.8.8.8"));
if (sizeof(array_diff($native, $resolv)) || sizeof(array_diff($resolv, $native))) {
    echo "Failed check for bcc.com MX records\n";
    var_dump($native);
    var_dump($resolv);
    exit(1);
}
// test tcp mode
$native = array_map("_ip", dns_get_record("bbc.com", DNS_A));
$resolv = array_map("_ip", _resolv_convert_results(_resolv_query_tcp("bbc.com", 5, "8.8.8.8", _resolv_convert_query(DNS_A))[1], "bbc.com"));
if (sizeof(array_diff($native, $resolv)) || sizeof(array_diff($resolv, $native))) {
    echo "Failed TCP check for bcc.com A records\n";
    var_dump($native);
    var_dump($resolv);
    exit(1);
}
$native = array_map("_target", dns_get_record("bbc.com", DNS_MX));
$resolv = array_map("_target", _resolv_convert_results(_resolv_query_tcp("bbc.com", 5, "8.8.8.8", _resolv_convert_query(DNS_MX))[1], "bbc.com"));
if (sizeof(array_diff($native, $resolv)) || sizeof(array_diff($resolv, $native))) {
    echo "Failed TCP check for bcc.com MX records\n";
    var_dump($native);
    var_dump($resolv);
    exit(1);
}