VB.Net Tutorial/Socket Network/Socket Port

Материал из VB Эксперт
Перейти к: навигация, поиск

Port scan

Imports System.Net.Sockets
Imports System.Net
Imports System.Threading
Imports System.Text
Public Class Tester
    Public Shared Sub Main
        Dim intPortStart As Integer = 1
        Dim intPortEnd As Integer = 10
        Dim lngLoop As Long
        For lngLoop = intPortStart To intPortEnd
            Dim myTcpClient As New TcpClient()
            Try
                myTcpClient.Connect("127.0.0.1", lngLoop)
                Console.WriteLine("Port " + lngLoop.ToString() + "started")
                myTcpClient.Close()
            Catch ex As SocketException
                Console.WriteLine("Port " + lngLoop.ToString() + " Closed" + ex.Message)
            End Try
        Next
    End Sub
End Class
Port 1 ClosedNo connection could be made because the target machine actively refused it
Port 2 ClosedNo connection could be made because the target machine actively refused it
Port 3 ClosedNo connection could be made because the target machine actively refused it
Port 4 ClosedNo connection could be made because the target machine actively refused it
Port 5 ClosedNo connection could be made because the target machine actively refused it
^CTerminate batch job (Y/N)? n