The Function PortInUse will check and see if the port you type in the text box is in use.You can adjust this code to check all your ports to determine what ports are in use.

Add a command button and a text box to your project. Then cut and past the code below. To test the code type in 21 in the text box if you do not have a FTP program running, then you will get a message that the port is ok to use. If you type in 23 you will get the above message if you do not have a telnet program running.

To get a list of well known TCP/IP ports check out the link below.

http://www.iana.org/assignments/port-numbers

===============================================
Option Explicit

Private Sub Command1_Click()
If PortInUse(Val(Text1)) Then
MsgBox "Port is not in use"
Else
MsgBox "Port in use"
End If
End Sub

Private Function PortInUse(ByVal PortNumber As Integer) As _
Boolean

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

'if we get this error, it means
'port is busy
bAns = Err.Number = 10048
oSocket.Close
Set oSocket = Nothing
PortInUse = bAns

End Function