Zjištění používaných TCP/IP portů

Postup:
Založte nový projekt, přidejte komponentu Winsock a ještě na formulář přidejte Timer, 2 jmenovky, ListBox, TextBox a dvě tlačítka. Label1 umístněte nad Text1 a Label2 nad ListBox1. Pro List1 nastavte Sorted = True. Nyní zapište následující kód:
Const PortsChecked = 200

Private Sub Command1_Click()

   Timer1.Enabled = True
   Timer1.Interval = 1000

End Sub

Private Sub Command2_Click()

   Timer1.Interval = 0
   Timer1.Enabled = False

End Sub

Private Sub Timer1_Timer()

   Dim X As Integer

   List1.Clear
   For X = 1 To PortsChecked
      DoEvents
      Text1.Text = X
      WinSock1.LocalPort = X
      On Error Resume Next
      WinSock1.Listen 
'Dostaneme-li chybu, je port používán.
      If Err.Number = 10048 Then
         List1.AddItem X 
'Zápis čísla portu do seznamu.
         Err.Number = 0
      End If

      WinSock1.Close
   Next X

End Sub

Private Sub Form_Load()

   Label1.Caption = "Test portu #"
   Label2.Caption = "Používané porty"
   Command1.Caption = "Start"
   Command2.Caption = "Stop"
   Text1.Locked = True

End Sub 

Zpět

Autor: The Bozena