24 | 03 | 2017

Check if port is in Use

Use to function below to check if a port is in use. For instance to test port 80 IsPortinUse(80) will return a true/false status.

Private Function IsPortinUse(ByVal PortNumber As Integer) As Boolean
'*************************************
'**** Code from VisibleVisual.co' ****
'*************************************
Dim oSocket As Object
Dim bAns As Boolean
 
On Error Resume Next
Set oSocket = CreateObject("MSWinsock.Winsock.1")
 
    If Err.Number > 0 Then
        Err.Raise 30000, , "Could not create winsock object"
        Exit Function
    End If
 
Err.Clear
 
oSocket.LocalPort = PortNumber
oSocket.Listen
 
bAns = Err.Number = 10048 'port is busy
oSocket.Close
Set oSocket = Nothing
IsPortinUse = bAns
 
End Function
Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2206761
Latest Articles