我尝试使用Net_DNS2将域解析为ip地址。
public function updateStatus(){
try {
//Works
$resolver = new Net_DNS2_Resolver(array(
'nameservers' => array(37.235.1.177),
'use_tcp' => false,
'timeout' => 20
));
$resp = $resolver->query("swisscom.ch", 'A');
echo "swisscom.ch ip: " .$resp->answer[0]->address;
//Triggers timout exception :(
$resolver2 = new Net_DNS2_Resolver(array(
'nameservers' => array(195.186.4.162),
'use_tcp' => false,
'timeout' => 20
));
$resp2 = $resolver2->query("swisscom.ch", 'A');
echo "swisscom.ch ip: " .$resp2->answer[0]->address;
} catch (Exception $e) {
echo "<br />";
print_r ($e);
echo "<br />";
}
}
我尝试了两个不同的DNS服务器,37.235.1.177
按预期工作,但195.186.4.162
触发了此异常:
Net_DNS2_Exception Object ( [_request:Net_DNS2_Exception:private] => [_response:Net_DNS2_Exception:private] => [message:protected] => timeout on read select() [string:Exception:private] => [code:protected] => 203 [file:protected] => /home/user/public_html/projects/Net/DNS2.php [line:protected] => 1091 [trace:Exception:private] => Array ( [0] => Array ( [file] => /home/user/public_html/projects/Net/DNS2.php [line] => 1393 [function] => generateError [class] => Net_DNS2 [type] => -> [args] => Array ( [0] => 2 [1] => 195.186.4.162 [2] => 203 ) ) [1] => Array ( [file] => /home/user/public_html/projects/Net/DNS2.php [line] => 972 [function] => sendUDPRequest [class] => Net_DNS2 [type] => -> [args] => Array ( [0] => 195.186.4.162 [1] => �Sswisscomch ) ) [2] => Array ( [file] => /home/user/public_html/projects/Net/DNS2/Resolver.php [line] => 211 [function] => sendPacket [class] => Net_DNS2 [type] => -> [args] => Array ( [0] => Net_DNS2_Packet_Request Object ( [rdata] => [rdlength] => [offset] => 29 [header] => Net_DNS2_Header Object ( [id] => 59475 [qr] => 0 [opcode] => 0 [aa] => 0 [tc] => 0 [rd] => 1 [ra] => 0 [z] => 0 [ad] => 0 [cd] => 0 [rcode] => 0 [qdcount] => 1 [ancount] => 0 [nscount] => 0 [arcount] => 0 ) [question] => Array ( [0] => Net_DNS2_Question Object ( [qname] => swisscom.ch [qtype] => A [qclass] => IN ) ) [answer] => Array ( ) [authority] => Array ( ) [additional] => Array ( ) [_compressed:Net_DNS2_Packet:private] => Array ( [swisscom.ch] => 12 [ch] => 21 ) ) [1] => ) ) [3] => Array ( [file] => /home/user/public_html/projects/sqlInterface.php [line] => 34 [function] => query [class] => Net_DNS2_Resolver [type] => -> [args] => Array ( [0] => swisscom.ch [1] => A ) ) [4] => Array ( [file] => /home/user/public_html/projects/dnsQuery.php [line] => 7 [function] => updateStatus [class] => DBInterface [type] => -> [args] => Array ( ) ) ) [previous:Exception:private] => )
我已根据以下内容增加了timeoutlimit: https://netdns2.com/documentation/net_dns2-options/ 但它没有帮助。任何人都知道出了什么问题?
是的,两个DNS服务器都已启动并运行。
//编辑:
echo "::query() failed: ", $e->getMessage(), "\n";
等于:
::query() failed: timeout on read select()
答案 0 :(得分:0)
上面的代码没有任何问题。 事实上,来自ISP的一些DNS服务器拒绝来自非客户ips的查询请求。 这导致了超时。