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

͵Դҷҧ 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 6 0

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

Google   
g2gnet.com
Ҵѡ:  

ᨡ Scan Ţ IP Address - VB6

Category »  VB 6/VB.Net
: Webmaster 2/7/2553   : 12:43
(ҹ : 27786) 
ѹѧ ...
ǹ˹觢ͧ¹͵ǨͺʶҹС͹Ź ͧäԵ˹ Spam 䫵ͧ м红 Web DataBase ͡ GMail Logging File ͧ Server ͧº ش¡ѹѷ к Network ˹㹡ا෾ Ҹ (ѹҴͧ Fix IP 203.130.134.xxx ѷϢͧѹ) 鹾ͼ֡ҡз ¡еǨ ͧ ... 50 ҵ 10 Ҽͧѡҹúҧ ... !!! ... ͧ Тŷѹ硷͹ԡ աѧͧ ͤкءҧ ǡѹ仡ǡѹ ... Шԧ 觷ѹ ᷺ռõ Server ФѺ (лѭҷҧ ਵѹ ѹԴ ) ... ͫҷӺحӷҹµԹǷͧһ ...
Ƕ֧ɮբͧк͢¹ФѺ ѹҢͧҡ Ѻؤ¹ ... ǹԧӧҹѺ PING DOS Command ФѺ ... Ѻ Visual Basic 6 Ҩй Winsock Control (MSWINSCK.OCX) ҹ
    ѡɳС÷ӧҹ ѧ
  • ˹Ţ IP Address Ţ Port Ѻ Winsock
  • ҡ Connect ѧͧ·ҧҡ˹
  • ҡ Winsock öԴ͡Ѻͧ·ҧ ѹСⴴ价ӧҹѧ˵ءó ( ) Winsock_Connect() ҡöҢ IP Address ʴ繡 On 㹷ҧѺѹҡ͡ѹ ѹѧ˵ءó Connect
  • ҡҡǹ Loop Ѻ IP Address ҨҨФú ... (ͧ¨ԧ)
  • ѧࡵ ǹ Loop ͧ÷ӧҹͧ Timer Ҫ¹ФѺ ǡ For, Do, While ѡɳй ѹǢͧѺͧͧҴ
鴵ǹöͺ (Connect) ͢ LAN (Local Area Network) ѧöǨͺ͡ѧк͢Թ¹ФѺ ͺ͡Ѻͺ͡ ... 駹ҡ ҹ MAC Address ͢ LAN ҹ ͤѺ ҹ MAC Address ੾ǧ LAN ҹ鹹ФѺͧ ... óҡҹ MAC Address ǧ LAN Ҵ ԭԿ¡ѹͧдǡФѺ

IP Address ͧ Է෤վШ й˹ 繵ҧѺ (ҤѺ ... IP ʴҨ) ǹͧ DNS (Domain Name Server) 繹蹤 ŧҡ IP Address ҤѺ (¡ҡèŢ IP Address ͧ) 㹺شѧ ѹͺ˹ҡǡѹФѺ ... ҡǨҡ 55555+
ǹŴ 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 Port (LAN Internet) - 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


    ѧͧͧ͹ (ͺҧѹҾ § )
  • IP: 192.168.1.1 - Router
  • IP: 192.168.1.11 - Windows Server 2003/MS SQL Server Backup Data
  • IP: 192.168.1.20 - ͧչѧѺͧͧ (Ѻ ѴѹШ) ͧѡҹ
  • IP: 192.168.1.100 - ҡѺ Dream Box (DM600 PVR) Ẻٷտ ... ж١ѹҼ TV LCD Bravia ͧ Sony дԺ ѹҡẺ˹Ǵ ѹҤҡѹ ... 55555+
  • IP: 192.168.1.21 - (Ҿҧҧ) ͧ鷴ͺҧ¹ 1 ҷԵŧ Windows XP ʹ
  • IP: 192.168.1.22 - (Ҿҧҧ) NoteBook ǹŧ Win 7 ͷͺա蹡ѹ

Run Time

Ҵ鴡ѹ ...

Option Explicit

' Ѻӹǹ IP Address Ǩ
Dim CountIP As Long

' 纤 IP شش¢ͧ  192.168.0.1 纤 1
Dim IPStartScan As Integer
' 纤 IP شش¢ͧش   192.168.0.254 纤 254
Dim IPEndScan As Integer

' 纤 IP 3 شá  192.168.0.254 纤 192.168.0 
Dim strIP As String

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

' óش Scan
Private Sub cmdStop_Click()
    ' ˹ False ش Scan IP Address
    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 = "0"
    
    txtEndIP(0).Text = "192"
    txtEndIP(1).Text = "168"
    txtEndIP(2).Text = "0"
    txtEndIP(3).Text = "255"
    
    txtPort.Text = "80"
    
    txtScanResult.Text = ""
    cmdStop.Enabled = False
    
End Sub

' ###################################################
' á Scan  IP Address
' ###################################################
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.Text) = "" Or Len(Trim$(txtPort.Text)) = 0 Then
        MsgBox "سһ͹Ţ Port ͹.", vbOKOnly + vbExclamation, "§ҹʶҹ"
        Exit Sub
    End If
    
    '  Status Bar  Panel á
    sbMain.Panels(1).Text = ""
    '  TextBox 㹡ʴŢ IP Address
    txtScanResult.Text = ""
    ' ҡùѺӹǹ IP
    CountIP = 0
    
    ' ˹ǧ㹡 Scan  IP Address
    ' ҧ駡Ҩеͧ˹ҹҹ ѹ鹡Ѻзҧ  ¹ФѺ
    Timer1.Interval = 100
    
    ' ҡ IP شش繤ҧ
    If Trim(txtEndIP(3).Text) <> "" Or Len(Trim(txtEndIP(3).Text)) = 0 Then
    
        cmdScan.Enabled = False
        cmdStop.Enabled = True
        
        ' Ţ Port
        txtScanResult.Text = txtScanResult.Text & "ǨͺŢ Port: " & txtPort.Text & vbCrLf
        
        ' ˹Ţ IP 㹡 Scan  ੾ 3 شá  192.168.0
        ' ǤӡùѺŢشش¢价 1
        strIP = txtStartIP(0).Text & "." & txtStartIP(1).Text & "." & txtStartIP(2).Text
        
        ' ˹Ţ IP Address  (شش)
        IPStartScan = txtStartIP(3).Text
        
        ' ˹Ţ IP ش (شش)
        IPEndScan = txtEndIP(3).Text
        
        ' йѧӡ Scan áҹդ False ش÷ӧҹŧѹ
        blnScan = True
        
        ' е鹹ԡӧҹ
        Timer1.Enabled = True
        
    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

' ###################################################
' 㹡 Scan  IP Address ǧ˹
' ###################################################
Private Sub ScanIP()

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

        ' ###################################################
        
        '  IP 㹡 Scan ա 1
        IPStartScan = IPStartScan + 1
        
    ' Scan  IP Address ú  ش Scan
    Else
        
        cmdScan.Enabled = True
        cmdStop.Enabled = False
        
        '  Timer1 ش÷ӧҹ
        Timer1.Enabled = False
        
        ' §ҹš Scan IP Address  StatusBar
        If IPStartScan <= IPEndScan Then
            sbMain.Panels(1).Text = "ش÷ӧҹ IP: " & IPStartScan
            
        ' ó Scan IP Address ó
        Else
            sbMain.Panels(1).Text = "÷ӧҹó - " & CountIP & " IP Address"
            MsgBox "Scan  IP к " & CountIP & " Ţ - Port " & txtPort.Text
        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 价ӧҹ ScanIP ҷ˹
    sbMain.Panels(1).Text = "ѧż IP: " & strIP & "." & IPStartScan
    
    '  Scan  IP Address 
    ' Ǩͺ Connect IP Address Ѻ Winsock Control ФѺ
    Call ScanIP

End Sub

' ###################################################
' 㹡õǨͺ Connect Ѻ Winsock 
' ҡա Connect Ѻ IP 跴ͺӡ駼 TextBox
Private Sub wsIP_Connect()
' ###################################################

On Error GoTo ErrorHandler
    
    ' ʴŢ IP Address  TextBox
    txtScanResult.Text = txtScanResult.Text & "IP : " & wsIP.RemoteHost & vbCrLf
    
    ' Ѻӹǹ IP Address Ǩ
    CountIP = CountIP + 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 frmIPScan = Nothing
    End
End Sub

Conclusion:
ҡ 繡ǹͺŢ IP Address ·ͺ§ 1 Port ҹ ... óշҡǨͺ Port ҧ ͧ IP Address 1 IP ᷹ ͧͧ ͧ աԴ Port ˹ҧ §˹ Fix IP Address § 1 Ţҹ ҡ鹡ǹͺŢ Port ᷹ ... ͧ任Ѻѹͧ¤Ѻ ... ҡ͡Ѻͧ ...

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