This commit is contained in:
sin365 2023-02-15 01:00:50 +08:00
parent 7fa4bc059f
commit a17979ba63
36 changed files with 455 additions and 0 deletions

View File

BIN
.vs/RCmd/v17/.suo Normal file

Binary file not shown.

31
RCmd.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RCmdC", "RCmdC\RCmdC.csproj", "{30C7A3A2-1742-4ADF-9EE3-3D2AEB85B83F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RCmdS", "RCmdS\RCmdS.csproj", "{6FC15228-663A-48E3-AE5D-FA4112EAC8B0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{30C7A3A2-1742-4ADF-9EE3-3D2AEB85B83F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30C7A3A2-1742-4ADF-9EE3-3D2AEB85B83F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30C7A3A2-1742-4ADF-9EE3-3D2AEB85B83F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30C7A3A2-1742-4ADF-9EE3-3D2AEB85B83F}.Release|Any CPU.Build.0 = Release|Any CPU
{6FC15228-663A-48E3-AE5D-FA4112EAC8B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6FC15228-663A-48E3-AE5D-FA4112EAC8B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6FC15228-663A-48E3-AE5D-FA4112EAC8B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6FC15228-663A-48E3-AE5D-FA4112EAC8B0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {513E4BEE-4FFE-4EFD-947A-731789B2A41F}
EndGlobalSection
EndGlobal

71
RCmdC/Program.cs Normal file
View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace RCmdC
{
internal class Program
{
private static Socket clientSocket = null;
private static Queue<string> cmdResultQueue = new Queue<string>();
private static void Main(string[] args)
{
clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// 客户端不需要绑定, 需要连接
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10492); //服务端IP和端口
clientSocket.Connect(endPoint);
Console.WriteLine("连接到服务器");
ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
{
byte[] buffer = new byte[1024];
while (true)
{
Array.Clear(buffer, 0, buffer.Length);
clientSocket.Receive(buffer);
string msg = Encoding.Default.GetString(buffer);
Console.WriteLine("收到消息: " + msg.Replace("\0", ""));
//Thread.Sleep(10);
}
}));
ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
{
while (true)
{
if (cmdResultQueue.Count > 0)
{
string cmd = cmdResultQueue.Dequeue();
Console.WriteLine("上传命令:" + cmd);
clientSocket.Send(Encoding.Default.GetBytes(cmd));
}
Thread.Sleep(10);
}
}));
while (true)
{
string cmdstr = Console.ReadLine();
if (string.IsNullOrEmpty(cmdstr))
{
Console.WriteLine("CMD命令不能为空:");
continue;
}
else
cmdResultQueue.Enqueue(cmdstr);
}
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Client")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Client")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("30c7a3a2-1742-4adf-9ee3-3d2aeb85b83f")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

48
RCmdC/RCmdC.csproj Normal file
View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{30C7A3A2-1742-4ADF-9EE3-3D2AEB85B83F}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Client</RootNamespace>
<AssemblyName>Client</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.0", FrameworkDisplayName = ".NET Framework 4")]

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
b9e2f5818204bdd53d14ebaabe7f49179a76e75e

View File

@ -0,0 +1,6 @@
D:\AxibugRCMD\AxiConC\bin\Debug\Client.exe
D:\AxibugRCMD\AxiConC\bin\Debug\Client.pdb
D:\AxibugRCMD\AxiConC\obj\Debug\AxiConC.csproj.AssemblyReference.cache
D:\AxibugRCMD\AxiConC\obj\Debug\AxiConC.csproj.CoreCompileInputs.cache
D:\AxibugRCMD\AxiConC\obj\Debug\Client.exe
D:\AxibugRCMD\AxiConC\obj\Debug\Client.pdb

Binary file not shown.

View File

@ -0,0 +1 @@
b9e2f5818204bdd53d14ebaabe7f49179a76e75e

View File

@ -0,0 +1,6 @@
D:\AxibugRCMD\Client\bin\Debug\Client.exe
D:\AxibugRCMD\Client\bin\Debug\Client.pdb
D:\AxibugRCMD\Client\obj\Debug\Client.csproj.AssemblyReference.cache
D:\AxibugRCMD\Client\obj\Debug\Client.csproj.CoreCompileInputs.cache
D:\AxibugRCMD\Client\obj\Debug\Client.exe
D:\AxibugRCMD\Client\obj\Debug\Client.pdb

Binary file not shown.

149
RCmdS/Program.cs Normal file
View File

@ -0,0 +1,149 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading;
using System.IO;
namespace RCmdS
{
internal class Program
{
private static Socket severSocket = null;
private static Process p;
private static Queue<string> cmdResultQueue = new Queue<string>();
private static Socket clientSocket;
private static void Main(string[] args)
{
p = new Process();
p.StartInfo.FileName = "cmd.exe"; //待执行的文件路径
p.StartInfo.UseShellExecute = false; //重定向输出这个必须为false
p.StartInfo.RedirectStandardError = true; //重定向错误流
p.StartInfo.RedirectStandardInput = true; //重定向输入流
p.StartInfo.RedirectStandardOutput = true; //重定向输出流
p.StartInfo.CreateNoWindow = false; //不启动cmd黑框框
p.Start();
severSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 10492);
severSocket.Bind(endPoint); // 绑定
severSocket.Listen(1); // 设置最大连接数
Console.WriteLine("开始监听");
//Console.WriteLine("进程ID"+Process.GetCurrentProcess().Id);
Thread thread = new Thread(ListenClientConnect); // 开启线程监听客户端连接
thread.Start("连接成功");
//Thread thread_1 = new Thread(TEST); // 开启线程监听客户端连接
//thread_1.Start("连接成功");
ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
{
while (true)
{
if (p != null && !p.HasExited)
{
StreamReader sr = p.StandardOutput;
string str = sr.ReadLine();
Console.WriteLine(str);
cmdResultQueue.Enqueue(str);
}
Thread.Sleep(10);
}
}));
ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
{
while (true)
{
if (p != null && !p.HasExited)
{
StreamReader sr = p.StandardError;
string str = sr.ReadLine();
Console.WriteLine(str);
cmdResultQueue.Enqueue(str);
}
//Thread.Sleep(10);
}
}));
ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
{
while (true)
{
if (clientSocket != null)
{
while (cmdResultQueue.Count > 0)
{
clientSocket.Send(Encoding.Default.GetBytes(cmdResultQueue.Dequeue()));
}
}
//Thread.Sleep(10);
}
}));
while (true)
{
string cmd = Console.ReadLine();
p.StandardInput.WriteLine(cmd);
Console.WriteLine("输出命令");
}
}
/// <summary>
/// 监听客户端连接
/// </summary>
private static void ListenClientConnect(object msg)
{
clientSocket = severSocket.Accept(); // 接收客户端连接
Console.WriteLine("客户端连接成功 信息: " + clientSocket.AddressFamily.ToString());
clientSocket.Send(Encoding.Default.GetBytes(msg.ToString()));
Thread revThread = new Thread(ReceiveClientManage);
revThread.Start(clientSocket);
}
private static void ReceiveClientManage(object clientSocket)
{
try
{
Socket socket = clientSocket as Socket;
byte[] buffer = new byte[1024];
while (true)
{
Array.Clear(buffer, 0, buffer.Length);
socket.Receive(buffer); // 从客户端接收消息
string cmd = Encoding.Default.GetString(buffer);
Console.WriteLine("收到消息:" + cmd);
cmd = cmd.Replace("\0", "");
Exec(cmd);
}
}
catch (SocketException)
{
//客户端断开重启
severSocket.Close();
severSocket.Dispose();
GC.Collect();
Process.Start(Process.GetCurrentProcess().MainModule.FileName);
Environment.Exit(0);
}
}
/// <summary>
/// 执行客户端发来的cmd命令
/// </summary>
/// <param name="cmd"></param>
private static void Exec(string cmd)
{
p.StandardInput.WriteLine(cmd);
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Server")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Server")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("6fc15228-663a-48e3-ae5d-fa4112eac8b0")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

48
RCmdS/RCmdS.csproj Normal file
View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6FC15228-663A-48E3-AE5D-FA4112EAC8B0}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Server</RootNamespace>
<AssemblyName>Server</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.0", FrameworkDisplayName = ".NET Framework 4")]

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
b9e2f5818204bdd53d14ebaabe7f49179a76e75e

View File

@ -0,0 +1,6 @@
D:\AxibugRCMD\AxiConS\bin\Debug\Server.exe
D:\AxibugRCMD\AxiConS\bin\Debug\Server.pdb
D:\AxibugRCMD\AxiConS\obj\Debug\AxiConS.csproj.AssemblyReference.cache
D:\AxibugRCMD\AxiConS\obj\Debug\AxiConS.csproj.CoreCompileInputs.cache
D:\AxibugRCMD\AxiConS\obj\Debug\Server.exe
D:\AxibugRCMD\AxiConS\obj\Debug\Server.pdb

Binary file not shown.

View File

@ -0,0 +1 @@
b9e2f5818204bdd53d14ebaabe7f49179a76e75e

View File

@ -0,0 +1,6 @@
D:\AxibugRCMD\Server\bin\Debug\Server.exe
D:\AxibugRCMD\Server\bin\Debug\Server.pdb
D:\AxibugRCMD\Server\obj\Debug\Server.csproj.AssemblyReference.cache
D:\AxibugRCMD\Server\obj\Debug\Server.csproj.CoreCompileInputs.cache
D:\AxibugRCMD\Server\obj\Debug\Server.exe
D:\AxibugRCMD\Server\obj\Debug\Server.pdb