111,076
社区成员




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Diagnostics;
namespace Server
{
class Program
{
static void Main(string[] args)
{
Socket S = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Byte[] IP = new byte[4] { 127, 0, 0, 1 };
int Port = 9999;
IPEndPoint ep = new IPEndPoint(new IPAddress(IP), Port);
//或者这样写 IPEndPoint ep1 = new IPEndPoint(IPAddress.Parse("127.0.0.1"), Port);
S.Bind(ep);
S.Listen(100);
Socket S1 = S.Accept();
Byte[] Content = new Byte[256];
int L = S1.Receive(Content);
String cmd = Encoding.UTF8.GetString(Content).Substring(0, L);
if (cmd.ToUpper() == "RUN")
{
Process.Start("NOTEPAD.EXE");
}
S.Close();
S1.Close();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace Client
{
class Program
{
static bool isConnected = false;
static void Main(string[] args)
{
Socket S = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
String cmd = string.Empty;
try
{
S.Connect(IPAddress.Parse("127.0.0.1"), 9999);
Console.WriteLine("请输入待传送的字符,输入Run,服务器端将执行NOTEPAD.EXE");
cmd = Console.ReadLine();
S.Send(Encoding.UTF8.GetBytes(cmd));
S.Close();
isConnected = true;
}
catch (Exception e)
{
Console.WriteLine("服务器未开启,等待链接中... ...");
Thread.Sleep(1000);
}
finally
{
if (isConnected == false) Main(null);
}
}
}
}
ManagementClass mc = new ManagementClass("win32_process");
mc.Scope.Options.Username = "user";
mc.Scope.Options.Password = "password";
mc.Scope.Path.Server = "192.168.1.5";
mc.InvokeMethod("Create", new object[] { @"c:\windows\notepad.exe" });