如何测试远程UDP端口 [英] How to test a remote UDP Port
问题描述
我要寻找一个简单的方法,如果一个远程的UDP端口是开放的服务器上
I am looking for a simple way to see if a remote UDP port is open on a server
推荐答案
要注意的是一些防火墙/网络设置/ IDS等可能影响结果......下面的方法不是100%可靠的,但它是唯一的方法可能与UDP恕我直言(因为UDP是无连接的)。的
您可以使用<一个href="http://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient.aspx"><$c$c>UdpClient$c$c>, 设置接收超时于底层的socket ,的让到远程服务器/端口的连接,的 发送
一些小消息(字节[]
!)和叫<一href="http://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient.receive.aspx"><$c$c>Receive$c$c>.
You can use UdpClient
, set a receive timeout on the underlying socket, make a connection to that remote server/port, Send
some small message (byte[]
!) and call Receive
.
如果该端口是关闭的,你得到一个异常说,连接被强制关闭( SocketException
与错误code
10054 = WSAECONNRESET
)...这意味着端口未打开。
IF the port is closed you get an exception saying that the connection was forcibly closed (SocketException
with ErrorCode
10054 = WSAECONNRESET
)... which means the port is NOT open.
否则,要么收到答案或超时异常 - 这两个应该是PTED为UDP端口是开放的跨$ P $
Otherwise you either receive an answer OR a timeout exception - both should be interpreted as "the UDP port is open".
这篇关于如何测试远程UDP端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!