三亚市城乡建设局网站安徽网站建设制作

张小明 2026/1/1 23:44:22
三亚市城乡建设局网站,安徽网站建设制作,微信如何建设网站,抖音推广方案C#实现的远程控制系统源码#xff0c;包含服务端和客户端实现#xff0c;支持命令执行、文件传输和基础安全认证#xff1a;一、服务端实现#xff08;支持多线程#xff09; using System; using System.Collections.Concurrent; using System.Net; using System.Net.Soc…C#实现的远程控制系统源码包含服务端和客户端实现支持命令执行、文件传输和基础安全认证一、服务端实现支持多线程usingSystem;usingSystem.Collections.Concurrent;usingSystem.Net;usingSystem.Net.Sockets;usingSystem.Security.Cryptography;usingSystem.Text;usingSystem.Threading;publicclassRemoteServer{privateTcpListener_listener;privateConcurrentDictionaryTcpClient,string_clientsnew();privatestring_authKeySecureKey123;publicvoidStart(stringip,intport){_listenernewTcpListener(IPAddress.Parse(ip),port);_listener.Start();Console.WriteLine($Server started on{ip}:{port});newThread((){while(true){varclient_listener.AcceptTcpClient();_newThread(()HandleClient(client)).Start();}}).Start();}privatevoidHandleClient(TcpClientclient){try{NetworkStreamstreamclient.GetStream();byte[]authBuffernewbyte[1024];intbytesReadstream.Read(authBuffer,0,authBuffer.Length);stringauthDataEncoding.UTF8.GetString(authBuffer,0,bytesRead);if(!VerifyAuth(authData)){client.Close();return;}_clients[client]Authorized;Console.WriteLine(Client authenticated: client.Client.RemoteEndPoint);while(true){bytesReadstream.Read(authBuffer,0,authBuffer.Length);if(bytesRead0)break;stringcommandEncoding.UTF8.GetString(authBuffer,0,bytesRead).Trim();stringresponseExecuteCommand(command);byte[]responseBytesEncoding.UTF8.GetBytes(response);stream.Write(responseBytes,0,responseBytes.Length);}}catch(Exceptionex){Console.WriteLine($Error:{ex.Message});}finally{_clients.TryRemove(client,out_);client.Close();}}privateboolVerifyAuth(stringauthData){string[]partsauthData.Split(|);if(parts.Length!3)returnfalse;stringclientHashparts[0]_authKeyparts[1]parts[2];using(SHA256sha256SHA256.Create()){byte[]hashBytessha256.ComputeHash(Encoding.UTF8.GetBytes(clientHash));stringserverHashBitConverter.ToString(hashBytes).Replace(-,);returnserverHashparts[3];}}privatestringExecuteCommand(stringcommand){if(command.ToLower()exit)returnGoodbye!;if(command.ToLower()gettime)returnDateTime.Now.ToString(yyyy-MM-dd HH:mm:ss);try{ProcessprocessnewProcess();process.StartInfo.FileNamecmd.exe;process.StartInfo.Arguments$/C{command};process.StartInfo.RedirectStandardOutputtrue;process.StartInfo.UseShellExecutefalse;process.Start();stringoutputprocess.StandardOutput.ReadToEnd();process.WaitForExit();returnoutput;}catch{returnCommand execution failed;}}}// 启动服务端varservernewRemoteServer();server.Start(0.0.0.0,8888);二、客户端实现带身份验证usingSystem;usingSystem.Net.Sockets;usingSystem.Security.Cryptography;usingSystem.Text;usingSystem.Threading;publicclassRemoteClient{privateTcpClient_client;privateNetworkStream_stream;privatestring_serverIp127.0.0.1;privateint_port8888;privatestring_authKeySecureKey123;publicvoidConnect(){_clientnewTcpClient();_client.Connect(_serverIp,_port);_stream_client.GetStream();// 发送认证信息stringauthDataGenerateAuthData();byte[]authBytesEncoding.UTF8.GetBytes(authData);_stream.Write(authBytes,0,authBytes.Length);newThread(ReceiveMessages).Start();}privatestringGenerateAuthData(){stringclientIdGuid.NewGuid().ToString();stringtimestampDateTime.Now.Ticks.ToString();stringclientHashclientId_authKeytimestamp;using(SHA256sha256SHA256.Create()){byte[]hashBytessha256.ComputeHash(Encoding.UTF8.GetBytes(clientHash));stringserverHashBitConverter.ToString(hashBytes).Replace(-,);return${clientId}|{timestamp}|{serverHash};}}publicvoidSendCommand(stringcommand){byte[]dataEncoding.UTF8.GetBytes(command);_stream.Write(data,0,data.Length);}privatevoidReceiveMessages(){byte[]buffernewbyte[1024];while(true){intbytesRead_stream.Read(buffer,0,buffer.Length);if(bytesRead0)break;stringresponseEncoding.UTF8.GetString(buffer,0,bytesRead);Console.WriteLine(Response: response);}}}// 使用示例varclientnewRemoteClient();client.Connect();client.SendCommand(gettime);Thread.Sleep(1000);client.SendCommand(exit);三、核心功能说明安全认证机制使用SHA-256哈希算法生成认证令牌 包含时间戳防重放攻击 动态生成客户端ID命令执行系统支持系统命令执行如dir、ipconfig 限制危险命令需扩展白名单机制 实时返回执行结果多线程架构服务端每个客户端独立线程处理 客户端异步接收响应四、扩展功能实现1. 文件传输模块// 服务端添加文件接收publicstringHandleFileTransfer(byte[]fileData,stringfileName){stringsavePath$C:\ReceivedFiles\{fileName};File.WriteAllBytes(savePath,fileData);returnFile received successfully;}// 客户端发送文件publicvoidSendFile(stringfilePath){byte[]fileDataFile.ReadAllBytes(filePath);stringfileNamePath.GetFileName(filePath);_stream.Write(Encoding.UTF8.GetBytes($FILE|{fileName}),0,1024);_stream.Write(fileData,0,fileData.Length);}2. 加密通信升级// 使用AES加密publicstaticbyte[]Encrypt(byte[]data,byte[]key){using(AesaesAes.Create()){aes.Keykey;aes.GenerateIV();using(CryptoStreamcsnewCryptoStream(newMemoryStream(),aes.CreateEncryptor(),CryptoStreamMode.Write)){cs.Write(data,0,data.Length);cs.FlushFinalBlock();}returnaes.IV.Concat(aes.Key).ToArray();}}// 在客户端和服务端添加加密层参考代码 C# 远程控制 实例源码(客户端服务端)www.youwenfan.com/contentcsn/92796.html五、安全增强方案双向证书认证使用X509证书验证客户端和服务端身份命令白名单privatereadonlystring[]_allowedCommands{gettime,systeminfo,tasklist};if(!_allowedCommands.Contains(command.ToLower()))returnCommand not allowed;流量监控publicclassTrafficMonitor{privatelong_totalBytesSent0;privatelong_totalBytesReceived0;publicvoidUpdateSent(longbytes)Interlocked.Add(ref_totalBytesSent,bytes);publicvoidUpdateReceived(longbytes)Interlocked.Add(ref_totalBytesReceived,bytes);}该方案实现了基础的远程控制功能可通过以下方式扩展添加图形化界面WPF/WinForm实现屏幕监控功能集成语音通讯模块开发移动端控制App
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

企业网站推广技巧和方法驾校门户网站模板

第一章:Open-AutoGLM实战指南:手把手教你搭建高精度酒店价格监测系统在动态定价日益重要的今天,构建一个自动化、高精度的酒店价格监测系统已成为旅游科技领域的关键能力。借助 Open-AutoGLM 强大的自然语言理解与结构化数据提取能力&#xf…

张小明 2025/12/25 17:43:28 网站建设

刘素云网站脱孝怎样做哈尔滨高端网站建设

【题目描述】如果二叉树的左右子树的结构是对称的,即两棵子树皆为空,或者皆不空,则称该二叉树是对称的。编程判断给定的二叉树是否对称.例:如下图中的二叉树T1是对称的,T2是不对称的。二叉树用顺序结构给出&#xff0c…

张小明 2025/12/25 17:42:24 网站建设

帝国cms 网站名称石家庄模板建站系统

LobeChat:构建私有化AI交互入口的技术实践 在生成式AI浪潮席卷各行各业的今天,一个现实问题摆在开发者和企业面前:如何在享受大语言模型强大能力的同时,不牺牲数据安全与系统可控性?市面上的主流对话产品虽然体验流畅&…

张小明 2025/12/25 17:41:51 网站建设

分类信息网站开发需求方案找人建个网站多少钱

Shell编程中 test 命令的使用与条件判断 在Shell编程中,条件判断是非常重要的一部分,它能让程序根据不同的情况执行不同的操作。而 test 命令在条件判断中扮演着关键角色。 1. test 命令基础 test 命令是一个内置的Shell命令,常用于测试一个或多个条件。其一般格式…

张小明 2025/12/25 17:40:46 网站建设