Check whether a port is open on a remote machine


Sometimes you would like to know whether a port is open on a remote machine. Now while this is no nmap, the following code should give you an idea on how to check whether a port is open.

Private Function isRemotePortOpen(ByVal hostName As String, ByVal port As Integer) As Boolean
    Dim client As TcpClient = Nothing
    Dim rtn as Boolean
        client = New TcpClient(Host, PortNumber)
        rtn = True
    Catch ex As SocketException
        rtn = False
        If Not client Is Nothing Then
        End If
    End Try
    Return rtn
End Function