Windows 防火墙阻止 ICMP 端口无法访问?
我正在尝试确定远程主机是否正在侦听特定的 UDP 端口号。我按如下方式执行此操作(在 C# 中):
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
int sent = socket.SendTo(bufsend, bufsend.Length, SocketFlags.None, endpoint);
int recv = socket.ReceiveFrom(bufrecv, ref endpoint);
如果没有人在侦听,我会收到 ICMP“端口无法访问”,该消息在接收时报告为套接字异常,错误代码为 WSAECONNRESET (10054)。所有这些都是有道理的,但只有在禁用 Windows 防火墙时才会发生。如果启用了防火墙——即使我为程序设置了例外——我会收到错误代码 WSAETIMEDOUT (10060),大概是因为防火墙已经占用了 ICMP“端口无法访问”。
有什么建议吗?我检查了防火墙的“高级安全”设置,但无济于事。
谢谢...
I'm attempting to determine whether or not a remote host is listening on a particular UDP port number. I do this (in C#) as follows:
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
int sent = socket.SendTo(bufsend, bufsend.Length, SocketFlags.None, endpoint);
int recv = socket.ReceiveFrom(bufrecv, ref endpoint);
If no one is listening, I get an ICMP "port unreachable" which is reported on the receive as a socket exception with ErrorCode WSAECONNRESET (10054). All that makes sense, BUT it only happens when the Windows firewall is disabled. If the firewall is enabled -- even if I make an exception for the program -- I get ErrorCode WSAETIMEDOUT (10060), presumably because the firewall has eaten the ICMP "port unreachable".
Any suggestions? I've examined the firewall "advanced security" settings, but to no avail.
Thanks...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅上面的评论。您必须将打开防火墙的规则应用于所有程序的“目标无法访问”消息,而不仅仅是实现 SendTo / ReceiveFrom 测试的可执行文件。
See the comment above. You must apply the rule opening the firewall to "destination unreachable" messages to ALL programs, not just to the executable that implements the SendTo / ReceiveFrom test.