版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、C#下局域网屏幕监控系统的实现摘 要 介绍了用C#工具在局域网中对各工作站的屏幕活动实时监控的实现思路与设计过程,并可以通过控制中心与各工作站进行信息沟通并控制客户端,为局域网的管理提供了一种技术支持,具有很好的借鉴作用。关键词 C#;局域网;屏幕监控;信息沟通 1 引言对于局域网管理员来说,实时查看网络中各个工作站的屏幕活动情况是很正常的工作,同时也需要对不符合网络要求的操作进行信息沟通。对于现场比较远的网络系统而言,频繁地到现场去检查监督很浪费精力,一个具有屏幕监控和信息传递的软件将会大大减轻网管人员的工作负担。2 实现思路为能更好地实现软件功能的设计,从以下几方面入手来进行规划设计:(1
2、) 采用客户端和控制台方式来设计软件,客户机和控制台依据功能要求分别设计软件,并分开安装。(2) 控制台软件采用C#下的Socket通信建立与客户端的通信连接,应包括屏幕监控、屏幕锁定/解锁、强制关机、信息传递等功能。也可以用一个文本文件或数据表按特定格式保存局域网内各工作站的IP地址。(3) 在对图像的处理方面,设定多线程对通过Socket传送来的数据保存为临时位图文件后在控制台界面里进行显示。(4) 尽可能对客户端运行的程序进行隐含运行,便于管理员的控制。3 程序界面程序设计过程采用了C#常用的控件,用Socket的通信方式对通信协议进行约定定义,达到通信握手的目的。在主控台的画面显示窗体
3、里判定传送过来的图片的大小,并适时调整。其主控界面如图1所示。 图1 服务端监控4 关键代码4.1 控制端代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Net;using System.Net.Sockets;using System.Threading;using System.Drawing;using Client;namespace RemoteControl public class RevThread public delegate v
4、oid displayRevData(Point left_top_point,Point right_bottom_point,Image data); public displayRevData display_rev_data_func; private const int local_port = 61002; private UdpClient rev_data_udp; private Thread rev_data_thread; public RevThread(displayRevData disp_function) this.display_rev_data_func =
5、 disp_function; ThreadStart ts = new ThreadStart(rev_data); rev_data_thread = new Thread(ts); rev_data_thread.Start(); public void send_monitor_to_client(string local_ip_address,string dest_ip_address) send_monitor_to_client(local_ip_address,dest_ip_address, false); public void send_monitor_to_clien
6、t(string local_ip_address,string dest_ip_address,bool send_all_screen) /IP地址及端口信息 string command_string = #IP: + local_ip_address + #IPEND#PORT: + local_port.ToString() + #PORTEND#; if (true = send_all_screen) command_string = command_string + #SENDALL#; /添加控制客户机的命令串,在客户端寻找ORDER:与CMD_END#之间的串 comman
7、d_string = command_string+ ORDER: + Program .order_string ; command_string = command_string + #CMD_END#; UdpClient sender = new UdpClient(); IPEndPoint endPoint = (new IPEndPoint(IPAddress.Parse(dest_ip_address), GlobalConsts.LOCAL_WAIT_PORT); try byte bytes = Encoding.ASCII.GetBytes(command_string)
8、; sender.Send(bytes, bytes.Length, endPoint); catch (Exception ex) Console.WriteLine(ex.ToString(); finally sender.Close(); private void rev_data() rev_data_udp = new UdpClient(new IPEndPoint(IPAddress.Any, local_port); IPEndPoint remoteHost = null;while (rev_data_udp != null & Thread.CurrentThread.
9、ThreadState.Equals(ThreadState.Running) try byte buf = rev_data_udp.Receive(ref remoteHost); /以下代码用于取出当前这个数据包对应的屏幕坐标数据 byte info = new byte50; Array.Copy(buf, 0, info, 0, 50); string info_data_str = Encoding.UTF8.GetString(info); int start_pos=info_data_str.IndexOf(#x_1:)+5; int end_pos=info_data_st
10、r.IndexOf(y_1:); int point_x = Convert.ToInt32(info_data_str.Substring(start_pos, end_pos - start_pos); start_pos = end_pos + 4; end_pos = info_data_str.IndexOf(x_2:); int point_y = Convert.ToInt32(info_data_str.Substring(start_pos, end_pos - start_pos); Point left_top_point = new Point(point_x, poi
11、nt_y); start_pos = end_pos + 4; end_pos = info_data_str.IndexOf(y_2:); point_x = Convert.ToInt32(info_data_str.Substring(start_pos, end_pos - start_pos); start_pos = end_pos + 4; end_pos = info_data_str.IndexOf(#); point_y = Convert.ToInt32(info_data_str.Substring(start_pos, end_pos - start_pos); Po
12、int right_bottom_point = new Point(point_x, point_y); byte image_bytes = new bytebuf.Length-50; Array.Copy(buf, 50, image_bytes, 0, image_bytes.Length); Image data = Screen.BytesToImg(image_bytes); if (null != display_rev_data_func) display_rev_data_func(left_top_point,right_bottom_point,data); catc
13、h (Exception e) Console.WriteLine(e.ToString(); private static string getLocalIPAddress() System.Net.IPAddress addr; / 获得本机局域网IP地址 addr = new System.Net.IPAddress(Dns.GetHostEntry(Dns.GetHostName().AddressList0.GetAddressBytes(); return addr.ToString(); public void stop() rev_data_thread.Abort(); re
14、v_data_udp.Close(); private void button1_Click(object sender, EventArgs e)/屏幕监控按钮 if (textBox1.Text.Length 5) MessageBox.Show(被监控的客户端IP地址不允许空, 确信正确, MessageBoxButtons.OK); return; Program.order_string = ;/命令串,代表发送指令内容,为空则不操作客户端 rev_thread.send_monitor_to_client(comboBox1.Text, textBox1.Text); privat
15、e void button3_Click(object sender, EventArgs e) if (textBox1.Text.Length 5) MessageBox.Show(被监控的客户端IP地址不允许空, 确信正确, MessageBoxButtons.OK); return; Program.order_string = LOCK; rev_thread.send_monitor_to_client(comboBox1.Text, textBox1.Text); private void button4_Click(object sender, EventArgs e) if
16、(textBox1.Text.Length 5) MessageBox.Show(被监控的客户端IP地址不允许空, 确信正确, MessageBoxButtons.OK); return; Program.order_string = UNLOCK; rev_thread.send_monitor_to_client(comboBox1.Text, textBox1.Text); private void button5_Click(object sender, EventArgs e) if (textBox1.Text.Length 5) MessageBox.Show(被监控的客户端IP
17、地址不允许空, 确信正确, MessageBoxButtons.OK); return; Program.order_string = CLOSEPC; rev_thread.send_monitor_to_client(comboBox1.Text, textBox1.Text); private void button6_Click(object sender, EventArgs e) if (textBox1.Text.Length 5) MessageBox.Show(被监控的客户端IP地址不允许空, 确信正确, MessageBoxButtons.OK ); return; Pro
18、gram.order_string = RESTART; rev_thread.send_monitor_to_client(comboBox1.Text, textBox1.Text); private void button7_Click(object sender, EventArgs e) if (textBox1.Text.Length 5) MessageBox.Show(被监控的客户端IP地址不允许空, 确信正确, MessageBoxButtons.OK); return; Program.order_string = NO LINK; rev_thread.send_monitor_to_client(comboBox1.Text, textBox1.Text); private void button8_Click(object sender, EventArgs e) if (textBox1.Text.Length 0) send_all_screen = true; IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(ip_address), port); SendDataThread send_thread = new SendDataThre
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025 高中信息技术数据与计算之数据在社交媒体内容质量评估中的应用课件
- 2026年深海采矿车试验验证与标准体系建设指南
- 2026年海绵城市设施“日常管养 季度清理 年度评估”操作实务
- 2026年工业元宇宙从三维展板向生产核心渗透实践
- 2026年起降场噪声暴露评估与隔音屏障设置建议
- 2026年心怀国之大者将宏观战略拆解具体任务操作手册
- 2026年银发经济示范区家庭医生签约与上门巡诊操作实务
- 2026年数据产品描述与数据产品质量评价标准规范研制指南
- 购置补贴是高频搜索词:湖北省2026年3月刚调整植保无人机补贴额
- 2026年造血干细胞移植供者选择与预处理方案优化指南
- 最科学养羊技术
- 优质课一等奖初中家庭教育《青少年成才优秀家庭教育案例:家庭春雨 润物无声》
- 如何保证伙伴成功举绩
- GB/T 41155-2021烧结金属材料(不包括硬质合金)疲劳试样
- 发展经济学 马工程课件 0.绪论
- GB/T 17989.2-2020控制图第2部分:常规控制图
- GB/T 17492-2019工业用金属丝编织网技术要求和检验
- GB 13614-2012短波无线电收信台(站)及测向台(站)电磁环境要求
- 风景园林工程课件第四章-园路
- (印刷服务项目投标)印刷服务质量保证措施
- 工程质量问责追责管理办法
评论
0/150
提交评论