[Release][VB6] Simple portscanner
Heyho,
this is my first release here. Im going to show you how to make a simple portscanner in VB6
So lets get started!
My form looks like this:

You need:
5 Labels (lblIp, lblFrom, lblTo, lblPorts, lblPercent)
3 Command Buttons (cmdScan, cmdStop, cmdClear)
1 List Box (lstPorts)
1 Timer (tScan)
1 Winsock-Control (wSock)
1 Progress Bar (prgScan)
How does a port scanner work?
Its really simple. The winsock control tries to connect to every port on the given IP. When a connection is etablished, the port will be added to the port list.
Now for the code
Let me know how you like it.
this is my first release here. Im going to show you how to make a simple portscanner in VB6

So lets get started!
My form looks like this:

You need:
5 Labels (lblIp, lblFrom, lblTo, lblPorts, lblPercent)
3 Command Buttons (cmdScan, cmdStop, cmdClear)
1 List Box (lstPorts)
1 Timer (tScan)
1 Winsock-Control (wSock)
1 Progress Bar (prgScan)
How does a port scanner work?
Its really simple. The winsock control tries to connect to every port on the given IP. When a connection is etablished, the port will be added to the port list.
Now for the code
Code:
Dim iPortcount As Integer, iScancount As Integer
Code:
Private Sub cmdStop_Click() tScan.Enabled = False End Sub
Code:
Private Sub cmdClear_Click() lstPorts.Clear End Sub
Code:
Private Sub wSock_Connect() lstPorts.AddItem wSock.RemotePort End Sub
Code:
Private Sub txtFrom_KeyPress(KeyAscii As Integer)
If InStr("1234567890" & Chr$(8), Chr$(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Sub
Private Sub txtIp_KeyPress(KeyAscii As Integer)
If InStr("1234567890." & Chr$(8), Chr$(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Sub
Private Sub txtTo_KeyPress(KeyAscii As Integer)
If InStr("1234567890" & Chr$(8), Chr$(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Sub
Code:
Private Sub cmdScan_Click()
On Error Resume Next
iPortcount = CInt(txtTo.Text) - CInt(txtFrom.Text)
iScancount = 0
prgScan.Max = iPortcount
If txtIp.Text <> "" Then
If txtFrom.Text <> "" And txtTo.Text <> "" Then
If CInt(txtFrom.Text) < CInt(txtTo.Text) Then
tScan.Enabled = True
Else
MsgBox "Start port must be higher than the last port", vbCritical, "Error"
End If
Else
MsgBox "Please specify a portrange to scan", vbCritical, "Error"
End If
Else
MsgBox "Please insert an IP to scan", vbCritical, "Error"
End If
End Sub
Code:
Private Sub tScan_Timer()
On Error Resume Next
Dim iPercent As Integer
wSock.Close
If (iScancount >= iPortcount) Then
MsgBox "All ports scanned!", vbInformation, "Success"
tScan.Enabled = False
Exit Sub
End If
txtFrom.Text = txtFrom.Text + 1
wSock.RemoteHost = txtIp.Text
wSock.RemotePort = txtFrom.Text
wSock.Connect
iScancount = iScancount + 1
prgScan.Value = iScancount
iPercent = (iScancount / iPortcount) * 100
lblPercent = iPercent & "%"
End Sub
