Click to See Complete Forum and Search --> : Port Scanner
Jeroen Vreuls
Mar 9th, 2000, 03:20 AM
Hello,
I am still a newbie, but I was wondering if anybody knows how to use the winsock control to make some kind of a port scanner. Not for hacking, but just for fun.
Thanks.
Raggart
Mar 10th, 2000, 12:39 AM
Right... For fun... :)
Winsock1.remotehost = [Address to scan]
Then you loop through the ports you want to scan:
for i = 1 to [MaxPort]
Winsock1.remoteport = i
loop
Don't forget to set the Error and Connect event. You must specify something like Winsock1.close in the Error & Connect Event so that when the socket connects, it closes itself so it can continue scanning.
In the Connect Event, you must also put code to specify that you connected successfully to the port.
And you're done.
Raggart
Jeroen Vreuls
Mar 11th, 2000, 02:05 AM
I've come up with the following code:
Dim i As Integer
Private Sub Command1_Click()
For i = 1 To 9000
Winsock1.RemotePort = i
Text1.Text = i
Next i
End Sub
Private Sub Form_Load()
Winsock1.RemoteHost = "127.0.0.1"
End Sub
Private Sub Winsock1_Connect()
Winsock1.Close
MsgBox "Port :" & i
End Sub
Private Sub Winsock1_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)
Winsock1.Close
Text1.Text = "Error"
End Sub
The problem is, it doesn't work. The For-Next loop loops fine, but it doesn't detect any open ports.
Could you tell me what's wrong with this code?
Thanks.
FirePoweR
Mar 12th, 2000, 08:25 AM
In the For..Next loop you have to put in the Connect command.
For i = 1 To 65535
Winsock1.RemotePort = i
Text1.Text = i
Winsock1.Connect
Next i
And the highest port number is 65535.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.