ҡդӶ ʵŧ 纺촨շ٨絴͵ ᷹ФѺ

͵Դҷҧ Inbox Ѻ

˹ѡ
-
VB 6/VB.Net
ASP/ASP.Net
Ѻ¤
¹ҹ Flash Movie
ռͺش  
 RSS Feeds
 ǹŴ RSS Reader ...   Download  RSS Reader

Forum - www.g2gnet.com
Webmaster - www.g2gnet.com
Visitors - Session views
 5 6 1 6 1 1 8

7 ѹҤ ..2549
72 Users On-Line.
Visitors - Page views
 8 9 7 3 8 6 1
1 Ҿѹ ..2551

Google   
g2gnet.com
Ҵѡ:  

ᨡ Scan Port (LAN Internet) - VB6

Category »  VB 6/VB.Net
: Webmaster 5/7/2553   : 14:33
(ҹ : 23264) 
㹷ҧк͢ (Network) ... Port е ͧҧͧͧ͡ ըӹǹҴ 2 ¡ѧ 16 ҡѺ 65536 Port (դҧ 0 - 65535 ФѺ) ¤ҵŢҹ繤੾ ١˹Ǣͧ Port ѹͧӧҹ Port 20/21 Ѻ FTP (File Transfer Protocal) 㹡͹ Port 80 Ѻ HTTP (Hyper Text Transfer Protocol) 繡ҹ Web Browser ͧѺ ... ੾к͢ҹ ػó;ǧ ѹͧ Port Ѻ觢͹ѹ COM Port Paralell Port ѧФѺ ... ѡͧ ҢͧաФѺ
    ªͧ¹Ǩͺ Scan Port ҹͧ
  • Ѻк͢ öǨͺͧ (Client) к LAN ͧ˹Դ Port Ӥѭ ѹ ·ͧ仹˹Ҩͧͧ͢ Port TCP UDP 135 ͧ DCOM RPC (Windows Distributed Component Object Model Remote Procedure Call) Port ˹͹ W32.Blaster.Worm ءҹ ... ֧кö仨Ѵͧ Client ѹǧ ͹ء仡͡ǹк͢·
  • 繼ŧҹͧкͧ ǹ˭ѡҢͧըҡҧҹ ФѺ ҧͧá͹ҧǴ 㹡ù Software ҡ¹͡ҹ ... ѹ繪ͧҧԴҹʹͧҹǤԴҧäѧФѺ (͹ʹյ·ǤѺ)
  • ¹ ֡ ҡͧԧ ʺóԧ ... зաþѲҢմöͧͧ͡ա ... ҵǡ鹵ФѺ (Value Add) ...
ǹŴ Source Code Ѻҹ Visual Basic 6
ǹŴ Source Code Ѻ MS Visual Basic 6.0 - Service Pack 6
 ǹŴ Visual Basic 6.0 SP5: Run-Time Redistribution Pack
 ǹŴ Microsoft Data Access Object (MDAC) Jet 4.0 Update
 ǹŴ Microsoft Visual Basic Service Pack 6

ᨡҹ IP Address DNS (LAN Internet) - VB6
ᨡ Scan Ţ IP Address - VB6
ҹ MAC Address ͢ LAN - VB6
Դ͹鹵͹ Debug Program MS Visual Basic 6.0
ͧͧ (ա) ... Sub Program, Routine, Procedure Function
¹ MAC Address (Media Access Control Address) Ẻ
VB6 Ѻҹ MAC Address ͧ LAN Card Ըպҹ ()

Component ա 2 ͡ҡ Project --> Components ...


Design Time


Run Time

Ҵ鴡ѹ ...

Option Explicit

' Ѻӹǹ Port Ǩ
Dim CountPort As Long

' 纤 Port   ҹ鹷 1 樹ҨФú
Dim PortToScan As Integer

' 纤 IP Address ͡˹Ѻ Winsock
Dim strIP As String

' 纤ʶҹТͧ Scan  Port
' ҡ繨ԧ ʶҹСѧ Scan
' ҡ ʶҹش Scan Ǥ
Dim blnScan As Boolean

' óش Scan Ǥ
Private Sub cmdStop_Click()
    ' ˹ False ش Scan Port
    blnScan = False
End Sub

Private Sub Form_Load()
    ' 駿觡ҧ
    Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
    
    ' Դ Timer ͹ ѧѹӧҹ
    Timer1.Enabled = False
    
    ' ҧФѺ
    txtStartIP(0).Text = "192"
    txtStartIP(1).Text = "168"
    txtStartIP(2).Text = "0"
    txtStartIP(3).Text = "1"
    
    ' Port 
    txtPort(0).Text = "1"
    ' Port ش
    txtPort(1).Text = "8000"
    
    txtScanResult.Text = ""
    cmdStop.Enabled = False
    
End Sub

' ###################################################
' á Scan  Port
' ###################################################
Private Sub cmdScan_Click()
    On Error GoTo ErrorHandler

    Dim Count As Integer
    
    ' Ǩͺ IP 㹡ä  4 ش 繤ҧ
    For Count = 0 To 3
        If Trim(txtStartIP(Count).Text) = "" Or Len(Trim(txtStartIP(Count).Text)) = 0 Then
            MsgBox "سһ͹Ţ IP Address ١ͧ.", vbOKOnly + vbExclamation, "§ҹʶҹ"
            Exit Sub
        End If
    Next Count
    
    ' Ǩͺһ͹Ţ Port   ش
    If Trim(txtPort(0).Text) = "" Or Len(Trim$(txtPort(0).Text)) = 0 Then
        MsgBox "سһ͹Ţ Port 鹡͹.", vbOKOnly + vbExclamation, "§ҹʶҹ"
        txtPort(0).SetFocus
        Exit Sub
    ElseIf Trim(txtPort(1).Text) = "" Or Len(Trim$(txtPort(1).Text)) = 0 Then
        MsgBox "سһ͹Ţ Port ش͹.", vbOKOnly + vbExclamation, "§ҹʶҹ"
        txtPort(1).SetFocus
        Exit Sub
    
    ' Port ش ͧդҡ Port 
    ElseIf Val(txtPort(0).Text) > Val(txtPort(1).Text) Then
        MsgBox "سһ͹Ţ Port شҡŢ Port 鹡͹.", _
                        vbOKOnly + vbExclamation, "§ҹʶҹ"
        txtPort(1).SetFocus
        Exit Sub
    End If
    
    '  Status Bar Panel á
    sbMain.Panels(1).Text = ""
    '  TextBox 㹡ʴŢ Port
    txtScanResult.Text = ""
    ' ҡùѺӹǹ Port
    CountPort = 0
    
    ' ˹ǧ㹡 Scan  Port ˹Թҷ  1000 ms = 1 Թҷ
    ' ҧ駡Ҩеͧ˹ҹҹ ѹ鹡Ѻзҧ  ¹ФѺ
    Timer1.Interval = 100
    
    cmdScan.Enabled = False
    cmdStop.Enabled = True
    
    ' 纤 IP Address 㹵 ͤдǡ㹡¡ҹ
    strIP = txtStartIP(0).Text & "." & txtStartIP(1).Text & "." & txtStartIP(2).Text & "." & txtStartIP(3).Text
    
    ' Ţ Port ѧ Scan Port
    txtScanResult.Text = txtScanResult.Text & "ǨͺŢ Port ͧ IP Address: " & strIP & vbCrLf
    
    ' ˹Ţ Port Ѻ ФҹͧҢ鹷 1 ҨФú
    PortToScan = txtPort(0).Text
    
    ' йѧӡ Scan áҹդ False ش÷ӧҹŧѹ
    blnScan = True
    
    ' е鹹ԡӧҹ
    Timer1.Enabled = True
    
ExitProc:
    Exit Sub
    
ErrorHandler:
    
    ' ѧӧҹ (Run Time) ѡ Error ҡ On Error GoTo ErrorHandler
    If Err.Number <> 0 Then MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
    Resume ExitProc
    
End Sub

' ###################################################
' 㹡 Scan  Port ǧ˹
' ###################################################
Private Sub ScanPort

    On Error GoTo ErrorHandler
    
    ' ͹ Scan Port ҡ Port 鹷˹  Ѻ鹷 1 樹ҨФú
    '  ѧաá cmdStop ش÷ӧҹ
    If PortToScan <= Val(txtPort(1).Text) And blnScan = True Then
        
        '  CPU 价ӧҹҧ (׹ CPU ѺѺкԺѵԡ - OS)
        DoEvents
        
        ' ҡ Winsock ѧա Connect Ѻ IP  ͧ Disconnect ͡仡͹
        If wsIP.State <> sckClosed Then wsIP.Close
        
        ' ###################################################
        ' ǹӤѭ˹ͷӡ÷ͺ
        
        ' ˹ IP Address Ѻ Winsock
        wsIP.RemoteHost = strIP
        
        ' ˹Ţ Port 㹡õԴ͡Ѻ Remote IP
        wsIP.RemotePort = PortToScan
        
        ' Winsock ԴŢ IP Address  Ţ Port ˹
        ' ǡöԴ IP Address  Port ˹ Сⴴ˵ءó wsIP_Connect()
        ' ҡҡѹʴŵŢ Port  Connect ͡ѧФѺ
        ' 繡÷ӧҹǹ سͧӡ Debug ٴ¹ФѺ ...
        wsIP.Connect
        
        ' ###################################################

        '  Port 㹡 Scan ա 1
        PortToScan = PortToScan + 1
        
    ' Scan  Port ú  ش Scan
    Else
        
        cmdScan.Enabled = True
        cmdStop.Enabled = False
        
        '  Timer1 ش÷ӧҹ
        Timer1.Enabled = False
        
        ' §ҹš Scan Port  StatusBar
        If PortToScan <= Val(txtPort(1).Text) Then
        
            sbMain.Panels(1).Text = "ش÷ӧҹ Port: " & PortToScan
            
            ' ˹ Port  ͨӡ Scan 
            txtPort(0).Text = PortToScan
            
        ' ó Scan Port ó
        Else
            sbMain.Panels(1).Text = "÷ӧҹó - " & CountPort & " Port"
            MsgBox "Scan  Port ͧŢ IP Address " & strIP & "  " & CountPort & " Port"
        End If
    End If
    

ExitProc:
    Exit Sub
    
ErrorHandler:
    
    ' ѧӧҹ (Run Time) ѡ Error ҡ On Error GoTo ErrorHandler
    If Err.Number <> 0 Then MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
    Resume ExitProc
    
End Sub

' ###################################################
' Һ㴷 Timer1.Enabled = True ѹҷӧҹ  Interval 
' ###################################################
Private Sub Timer1_Timer()
    ' ҡ Timer1 դ Enabled 价ӧҹ ScanPort ҷ˹
    sbMain.Panels(1).Text = "ѧż IP: " & strIP & "." & IPStartScan
    
    '  Scan  Port 
    ' Ǩͺ Connect IP Address/Port Ѻ Winsock Control ФѺ
    Call ScanPort

End Sub

' ###################################################
' óշ Winsock ö Connect ¤ wsIP.Connect
' ҡա Connect Ѻ IP 跴ͺӡ駼 TextBox
Private Sub wsIP_Connect()
' ###################################################

On Error GoTo ErrorHandler
    
    ' ʴŢ Port  TextBox
    txtScanResult.Text = txtScanResult.Text & "Port : " & wsIP.RemotePort & vbCrLf
    
    ' Ѻӹǹ Port Ǩ
    CountPort = CountPort + 1
    
ExitProc:
    Exit Sub

ErrorHandler:
    
    ' ѧӧҹ (Run Time) ѡ Error ҡ On Error GoTo ErrorHandler
    If Err.Number <> 0 Then MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
    Resume ExitProc

End Sub

Private Sub cmdExit_Click()
    Set frmPortScan = Nothing
    End
End Sub
Conclusion:
ͤԴ㹡þѲҵ .... ҡ鴹 Ѵ Logging File سöҴٵҧ Save Text File 駨ҡ䫵ͧ ºѺ ... ա駼¹鴵Ǩͺѹա (Connect) Ѻͧ·ҧ¹ФѺ ͧѺ ͧ 繡þѲҵ-ʹ͡աѺ ... ͧ

͵ - g2gNet Dot Com
Ţ¹ҳԪ硷͹ԡ 0407314800231
CopyLeft © 2004 - 2099 g2gNet.Com All rights reserved.
Email: [email protected] . 08-6862-6560