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