Visualizzazione dei risultati da 1 a 9 su 9

Discussione: [VB] Port scanner

  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2002
    Messaggi
    96

    [VB] Port scanner

    Avrei bisogno di costruire un programma in grado di visualizzare tutti i dato che viaggiano su una determinata porta (ad esempio: 80). C'è qualcuno che mi sa spiegare come si fa?

    Ciao, Andrea

  2. #2
    Utente di HTML.it L'avatar di vonkranz
    Registrato dal
    Sep 2001
    Messaggi
    1,387
    Devi usare il controllo Winsock.
    Ti consiglio di leggerti l'help ad esso collegato.

    Ciao.
    ...and I miss you...like the deserts miss the rain...

  3. #3
    Utente di HTML.it
    Registrato dal
    Apr 2002
    Messaggi
    96
    Ho provato a fare cosi ma non funziona...

    Private Sub Command1_Click()
    Winsock1.Close
    Winsock1.LocalPort = 80
    Winsock1.Listen
    End Sub

    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    Winsock1.Accept requestID
    End Sub

    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim Dati As String
    Winsock1.GetData Dati
    Text1.Text = Dati
    End Sub

    C'è qualcuno che mi sa spiegare come si fa?

  4. #4
    'Io faccio cosi:
    'Uno in ascolto(Winsock1)
    'Gli altri due comunicano
    '(Winsock2) 'Invia i Dati
    '(Winsock3) 'Riceve i Dati

    Private Sub Command1_Click()
    Winsock1.Close
    Winsock1.LocalPort = 80
    Winsock1.Listen
    End Sub

    Private Sub Command2_Click()
    Winsock2.SendData "CIAO"
    End Sub


    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    Winsock3.Accept requestID
    End Sub

    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim Dati As String
    Winsock3.GetData Dati
    Text1.Text = Dati
    Winsock3.SendData "Ho ricevuto i dati" & Dati & ")"
    End Sub

    Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
    Dim Dati As String
    Winsock2.GetData Dati
    MsgBox Dati
    End Sub

    'Ciao provalo non l' ho provato
    jabjoint

  5. #5
    Ah devi mettere la Accept anche per il "Winsock2"
    jabjoint

  6. #6
    Utente di HTML.it
    Registrato dal
    Apr 2002
    Messaggi
    96
    Ok...lo provo e ti faccio sapere...Grazie!

  7. #7
    Utente di HTML.it L'avatar di darkblOOd
    Registrato dal
    Jul 2001
    Messaggi
    2,212
    Originariamente inviato da Calem82
    Ok...lo provo e ti faccio sapere...Grazie!
    se mi mandi il tuo indirizzo e-mail ti mando i sorgenti del portscan che ho fatto io.

  8. #8
    Utente di HTML.it L'avatar di darkblOOd
    Registrato dal
    Jul 2001
    Messaggi
    2,212
    vabbè va:

    questo è il sorgente. Ovviamente non puoi fare solo copia-incolla, perchè ti macherebbero gli oggetti inseriti sul form. Meglio così, cosi fate lavorare il vostro cervello. Penso sia valido come oggetto di studio visto che tratta diverse cose.

    Ciao.

    codice:
    Dim PORT As Long
    Dim LASTPORT As Long
    Dim char As String
    Dim DA As Long
    Dim A As Long
    Dim cont As Integer
    Dim Scan As Integer
    Dim ScanType As String
    
    Private Sub ckRange_Click()
    If ckRange.Value = 1 Then
        txtDa.Enabled = True
        txtDa.BackColor = &HB99568
        txtA.Enabled = True
        txtA.BackColor = &HB99568
        txtDa.SetFocus
    End If
    If ckRange.Value = 0 Then
        txtDa = ""
        txtDa.Enabled = False
        txtDa.BackColor = frmScanner.BackColor
        txtA = ""
        txtA.Enabled = False
        txtA.BackColor = frmScanner.BackColor
    End If
    End Sub
    
    Private Sub cmdGo_Click()
    If cmdGo.Caption = "&Scan Now !" Then
        If txtHost = "" Then
            Beep
            txtHost.SetFocus
            Exit Sub
        End If
        If ckRange.Value = 0 Then
            PORT = 1
            LASTPORT = 65535
        End If
        If ckRange.Value = 1 Then
            If txtDa = "" Then
                MsgBox "Specificare un range valido!", vbExclamation, "Errore"
                txtDa.SetFocus
                Exit Sub
            End If
            If txtDa > 65535 Then
                MsgBox "Valore max= 65535", vbExclamation, "Errore"
                txtDa.SelStart = 0
                txtDa.SelLength = Len(txtDa)
                txtDa.SetFocus
                Exit Sub
            End If
            If txtA = "" Then
                MsgBox "Specificare un range valido!", vbExclamation, "Errore"
                txtA.SetFocus
                Exit Sub
            End If
            If txtA > 65535 Then
                MsgBox "Valore max= 65535", vbExclamation, "Errore"
                txtA.SelStart = 0
                txtA.SelLength = Len(txtA)
                txtA.SetFocus
                Exit Sub
            End If
            PORT = Trim(txtDa)
            LASTPORT = Trim(txtA)
            If LASTPORT - PORT < 0 Then
                MsgBox "Impossibile iniziare la scansione:" & Chr(13) & _
                       "La porta finale è minore della porta iniziale.", vbExclamation, "Errore"
                txtDa.SelStart = 0
                txtDa.SelLength = Len(txtDa)
                txtDa.SetFocus
                Exit Sub
            End If
        End If
        txtLog = ""
        cmdGo.Caption = "&Stop Scan"
        txtHost.Enabled = False
        txtDa.Enabled = False
        txtA.Enabled = False
        If ScanType = "Local" Then
            Scan = 10
            txtLog = "Start Local Scan..." + vbCrLf
        End If
        If ScanType = "Remote" Then
            Scan = 30000
            txtLog = "Start Remote Scan..." + vbCrLf
        End If
        mnuScan.Enabled = False
        ckRange.Enabled = False
        Scansione
    End If
    If cmdGo.Caption = "&Stop Scan" Then
        PORT = 0
        Winsock.Close
        cmdGo.Caption = "&Scan Now !"
        If ckRange.Value = 1 Then
            txtDa.Enabled = True
            txtA.Enabled = True
        Else
            txtDa.Enabled = False
            txtA.Enabled = False
        End If
        txtHost.Enabled = True
        txtHost.SelStart = 0
        txtHost.SelLength = Len(txtHost)
        txtHost.SetFocus
        mnuScan.Enabled = True
        ckRange.Enabled = True
    End If
    End Sub
    
    Sub Scansione()
    inizio:
    cont = Scan
    Winsock.RemoteHost = txtHost
    Winsock.RemotePort = PORT
    Winsock.Connect
    lblPORT.Caption = Winsock.RemotePort
    
    Stato:
    If Winsock.State = 0 Then
        If PORT = LASTPORT Then
            Winsock.Close
            txtLog = txtLog + "...End Scan" + vbCrLf
            mnuScan.Enabled = True
            ckRange.Enabled = True
            Exit Sub
        ElseIf PORT = 0 Then
            Winsock.Close
            txtLog = txtLog + "...Scan Stopped" + vbCrLf
            Exit Sub
        Else
            DoEvents
            PORT = PORT + 1
            GoTo inizio
        End If
    Else
        cont = cont - 1
        If cont = 0 Then
            Winsock.Close
        End If
        DoEvents
        GoTo Stato
    End If
    End Sub
    
    Private Sub cmdSave_Click()
    If txtLog = "" Then Exit Sub
    On Error GoTo NoLog
    CD.ShowSave
    Dim nFile As Integer
    nFile = FreeFile
    Open CD.FileName For Append As nFile
    Print #nFile, "------------------------------"
    Print #nFile, Now
    Print #nFile, Chr(13)
    Print #nFile, txtHost
    Print #nFile, Chr(13)
    Print #nFile, txtLog
    Print #nFile, Chr(13)
    Print #nFile, "------------------------------"
    Close #nFile
    Exit Sub
    NoLog:
    End Sub
    
    Private Sub Form_Load()
    frmScanner.Height = 4710
    frmScanner.Width = 2895
    cmdGo.Enabled = False
    cmdGo.Default = False
    txtHost = Winsock.LocalIP
    txtHost.SelStart = 0
    txtHost.SelLength = Len(txtHost)
    ckRange.Value = False
    txtDa.Enabled = False
    txtDa.BackColor = frmScanner.BackColor
    txtA.Enabled = False
    txtA.BackColor = frmScanner.BackColor
    ScanType = "Local"
    mnuLocal.Checked = True
    End Sub
    
    Private Sub Form_Resize()
    On Error Resume Next
    frmScanner.Height = 4710
    frmScanner.Width = 2895
    End Sub
    
    Private Sub mnuLocal_Click()
    mnuRemote.Checked = False
    mnuLocal.Checked = True
    ScanType = "Local"
    End Sub
    
    Private Sub mnuRemote_Click()
    mnuLocal.Checked = False
    mnuRemote.Checked = True
    ScanType = "Remote"
    End Sub
    
    Private Sub txtA_GotFocus()
    txtA.SelStart = 0
    txtA.SelLength = Len(txtA)
    End Sub
    
    Private Sub txtA_KeyPress(KeyAscii As Integer)
    If KeyAscii >= 48 And KeyAscii <= 57 Then
        char = Chr(KeyAscii)
        KeyAscii = Asc(char)
    ElseIf KeyAscii = 8 Then
        char = Chr(KeyAscii)
        KeyAscii = Asc(char)
    Else
        KeyAscii = 0
    End If
    End Sub
    
    Private Sub txtA_Validate(Cancel As Boolean)
    If txtA = "" Then Exit Sub
    If txtA > 65535 Then
        MsgBox "Valore max= 65535", vbExclamation, "Errore"
        txtA.SelStart = 0
        txtA.SelLength = Len(txtA)
        txtA.SetFocus
        Cancel = True
    End If
    End Sub
    
    Private Sub txtDa_GotFocus()
    txtDa.SelStart = 0
    txtDa.SelLength = Len(txtDa)
    End Sub
    
    Private Sub txtDa_KeyPress(KeyAscii As Integer)
    If KeyAscii >= 48 And KeyAscii <= 57 Then
        char = Chr(KeyAscii)
        KeyAscii = Asc(char)
    ElseIf KeyAscii = 8 Then
        char = Chr(KeyAscii)
        KeyAscii = Asc(char)
    Else
        KeyAscii = 0
    End If
    End Sub
    
    Private Sub txtDa_Validate(Cancel As Boolean)
    If txtDa = "" Then Exit Sub
    If txtDa > 65535 Then
        MsgBox "Valore max= 65535", vbExclamation, "Errore"
        txtDa.SelStart = 0
        txtDa.SelLength = Len(txtA)
        txtDa.SetFocus
        Cancel = True
    End If
    End Sub
    
    Private Sub txtHost_Change()
    If txtHost = "" Then
        cmdGo.Enabled = False
        cmdGo.Default = False
    Else
        cmdGo.Enabled = True
        cmdGo.Default = True
    End If
    End Sub
    
    Private Sub txtLog_Change()
    If txtLog = "" Then
        cmdSave.Enabled = False
    Else
        cmdSave.Enabled = True
    End If
    End Sub
    
    Private Sub Winsock_Connect()
    txtLog = txtLog + "host listen on port " & Winsock.RemotePort & vbCrLf
    Winsock.Close
    End Sub
    
    Private Sub Winsock_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    Winsock.Close
    End Sub

  9. #9
    Utente di HTML.it
    Registrato dal
    Apr 2002
    Messaggi
    96
    Ok...Grazie!!!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.