LagAbuse.com
Unofficial Section => Programming => Topic started by: JokeBOx on February 07, 2012, 20:16
-
Remote Desktop Viewer
Hello HF, this will be a fairly simple tutorial on how to code a Remote Desktop Viewer. You can use this to either make your own Team Viewer or implement it in a RAT for different purposes... it will be coded in reverse-connection and will use object serialization. I hope you will enjoy this 8) If you find any errors, please post and I will fix.
Client (Sender)
-Create a windows form project in VS or VB 2010/2008 and call it RDV Client.
-Add 2 buttons and label them Connect and Stream respectively.
-Add a timer and set it to 1000.
-Right click the form and select "View Code"
Header Code required to shortcut your main code.
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Drawing
Imports System.Runtime.Serialization.Formatters.Binary
This goes right below "Public Class Form1". They are global TCPClient and Networkstream to allow connection and streaming.
Dim client As New TcpClient
Dim nstream As NetworkStream
Now we make a function which returns the screenshot when called.
Public Function Desktop() As Image
Dim bounds As Rectangle = Nothing
Dim screenshot As System.Drawing.Bitmap = Nothing
Dim graph As Graphics = Nothing
bounds = Screen.PrimaryScreen.Bounds
screenshot = New Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
Return screenshot
End Function
Image sending function through serialization. It will call the screenshot and send it using the networkstream.
Private Sub SendImage()
Dim bf As New BinaryFormatter
nstream = client.GetStream
bf.Serialize(nstream, Desktop())
End Sub
Double click the timer and type this in to call SendImage function.
SendImage()
Double click the Connect button and add this. This will connect to localhost on port 8085.
Try
client.Connect("127.0.0.1", 8085)
Catch ex As Exception
MsgBox("Failed to connect...")
End Try
Double click the Stream button and add this to start the timer.
Timer1.start()
Conclusion: The client will connect to the server and stream images every 1 second. Done, now moving on to the server.
Server (Receiver)
-Create a windows form project in VS or VB 2010/2008 and call it RDV Server.
-Add a picturebox, fill dock it and change the sizemode to Stretch.
-Add 1 buttons and label it Listen. (if it dissapears try to bring it to front from the control panel)
-Right click the form and select "View Code"
Same imports as the last one.
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Drawing
Imports System.Runtime.Serialization.Formatters.Binary
Global Variables.. the only difference is that we make 2 threads now to prevent our window from lagging. One for listening and the other for receiving. Also we have the listening server.
Dim client As New TcpClient
Dim server As New TcpListener(8085)
Dim nstream As NetworkStream
Dim listening As New Thread(AddressOf Listen)
Dim getImage As New Thread(AddressOf receiveImage)
Receive Image and deserialize function (opposite to SendImage)
Private Sub receiveImage()
Dim bf As New BinaryFormatter
While client.Connected = True
nstream = client.GetStream
picturebox1.Image = bf.Deserialize(nstream)
End While
End Sub
Listening function to accept clients.
Private Sub Listen()
While client.Connected = False
server.Start()
client = server.AcceptTcpClient
End While
getImage.Start()
End Sub
Double click the Listen button.
listening.Start()
Conclusion: The server is ready to listen and accept any incoming connection. It will receive the images sent by the client.
How to use: Seriously? Open the client and server, click listen (server), then connect (client) and stream(client).
Note: If you wish to use this outside the local network, you might need to portforward the port you used and change the IP address.
I work on this 2 days and finaly finish!
-
Nice tutorial bro...
-
doesn't matter - if people are too lazy to research on it, it is easily accessible here.
-
good point... :P
-
nice tut master, I used it to multiple client and one server, just little modification but I want to know how to control it since that the program is just capturing the image only?.
-
Excellent Post master..
-
I was hoping you could tell me how to get rid of the mirror effect?
I was trying to fix this (Make it the way I wanted)
for example the client should be the one viewing the picturebox from the pc with the server on it.
At last I didnt get exactly what I wanted but its good enough
then I noticed the infinite mirror effect
where in the image it doubles on whatever windows is open
is there a way to fix this?
@lancasterjacob7@gmail.com
-
I'll try to create this program latter, good tut.
-
i try this code but i need to have 12 clients and view each clients desktop to one server form..
this is the flow that i want:
1. open server
2. once client pc is opened it automatically connect to server
3. then accept client 1 then view its desktop to picturebox 1
4. then client 2 to picturebox 2
5. client 3 to picture box 3 and so on,..
i try to do this but its not working
if clients.ipaddress="127.0.0.1" then
While clients.Connected = True
ns = client1.GetStream
PictureBox1.Image = bf.Deserialize(ns)
End While
else if clients.ipaddress="192.168.10.25" then
While clients.Connected = True
ns = clients.GetStream
PictureBox2.Image = bf.Deserialize(ns)
end while
else if clients.ipaddress="102.168.10.34" then
While clients.Connected = True
ns = clients.GetStream
PictureBox3.Image = bf.Deserialize(ns)
end while
end if.
i will make all clients ip static so the server can identify which client will getstream to a specif picture box..
i badly need your help..i hope you can reply as soon as possible..thanks in advance
-
hi sir! this is a good tutorial. thanks! i was trying to modify a little bit by having it support multiple receivers. a little help would be appreciated. thanks!
-
i cant get it to work