如何检查特定端口是否被 Windows 防火墙阻止,包括传入和传出连接。
我见过这样的代码示例:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim host As String = "localhost"
Dim port As Integer = 6900
Dim addr As IPAddress = CType(Dns.GetHostAddresses(host)(0), IPAddress)
Try
Dim tcpList As New TcpListener(addr, port)
tcpList.Start()
Catch sx As SocketException
' Catch exception here if port is blocked
End Try
End Sub
但是我怎么知道异常是不是因为防火墙阻塞而引发的,而不是因为其他套接字错误?