What the best way to go about creating a port listener and can someone please provide me with some code to get started?
Thanks,
Psyrus
Printable View
What the best way to go about creating a port listener and can someone please provide me with some code to get started?
Thanks,
Psyrus
Here is a few samples from planet-source-code.com of Port Listeners
Thanks Matthew I'll give it a look.
Does this look about right?
What I really want to do is to find out
if any files are either being sent from my computer
or received by my computer.
(Yes possible trojan)
CODE:
Private Sub Form_Load()
Winsock1.Listen
With txtInfo
.Text = .Text & "Local Port:" & Winsock1.LocalPort & " " & _
"LocalHost: " & Winsock1.LocalHostName
End With
txtStatus.Text = Winsock1.State
End Sub
Private Sub Form_Unload(Cancel As Integer)
Winsock1.Close
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock.Accept requestID
With txtInfo
.Text = .Text & "ID: " & requestID & vbNewLine
.Text = .Text & "RemoteHost: " & Winsock1.RemoteHost & vbNewLine & _
"RemotePort: " & Winsock1.RemotePort
End With
txtStatus.Text = Winsock1.State
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
txtStatus.Text = Winsock1.State
Winsock1.GetData strData, vbString
txtInfo.Text = txtInfo.Text & strData & vbNewLine & "Data Received!"
End Sub
Private Sub Winsock1_SendComplete()
txtStatus.Text = Winsock1.State
txtInfo.Text = txtInfo.Text & vbNewLine & "Illegal Data has been sent!"
End Sub
Here is an example on how to check 32000 ports to see if any of them are in use.
Code:'Required: 2 textboxes, command button, listbox, Winsock
'txtport1 = Text1
'txtport2 = Text2
Private Sub Command1_Click()
On Error Resume Next
Dim i As Long
For i = txtport1 To txtport2 Step 1 ' Set counter to start and End at a specified number.
Winsock1.Connect txtip, i ' connect To the ip and port
If Winsock1.State <> sckConnected Then 'if it could Not connect then its closed.
List1.AddItem i & " - closed"
End If
If Winsock1.State = sckConnected Then 'if it could connect its open.
List1.AddItem i & " - OPEN"
MsgBox "Open port!", vbCritical, "Port Scanner"
End If
Next i
End Sub
Private Sub Form_Load()
txtport1.Text = 1 'set default port values.
txtport2.Text = 32000
Winsock1.Protocol = sckTCPProtocol 'set protocol
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set form1 = Nothing 'clear memory
End Sub
Thanks again.
No message box popped up. I guess this means that there are no open ports? Is that all there are 32,000 ports to listen to?
I did get one error. The txtip wasn't defined anywhere so I set it to my computers name. Was that right?
Shouldn't port # 80 have been open since I am online?
Thanks,
Hmm, it should display some boxes, because I'm sure that one of your ports are open.
In a dosBox type:
netstat -a
and check which ports are open.
BTW: I think you should put txtIP to your own ip.
(you can find your ip by pressing START, RUN, then typing
winipcfg, you'll see your IP somewhere there
[Edited by Jop on 08-27-2000 at 09:41 PM]
The DOSPrompt shows 15 active connections with a STATE of either LISTENING or TIME_WAITING. Some local Addresses show nbsession, nbname or nbdatagram instead of the port number. There are three foreign addresses. one all 0's, and two normal ones. The protocols are either TCP or UDP.
Is this normal?
[Edited by psyrus on 08-27-2000 at 10:02 PM]