基于Sockets
没什么好说的,代码说明了所有
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.IO; namespace ConsoleApplication1
{
class Program
{
public static NetworkStream stream;
public static TcpClient tcpclient;
public static string ip;
public static int port;
static void Main(string[] args)
{
Console.WriteLine("目标IP:");
ip = Console.ReadLine();
Console.WriteLine("目标Port:");
port =int.Parse(Console.ReadLine()); Run();
} static public void Run()
{
tcpclient = new TcpClient(ip, port); // 连接服务器
stream = tcpclient.GetStream(); // 获取网络数据流对象
StreamWriter sw = new StreamWriter(stream);
StreamReader sr = new StreamReader(stream);
while (true)
{
//Read Echo
//Set ReadEcho Timeout
stream.ReadTimeout = ;
try
{
while (true)
{
char c = (char)sr.Read();
if (c < )
{
if (c == )
{
while (sr.Read() != ) { }
}
else
{
Console.Write(c);
}
}
}
}
catch
{ }
//Send CMD
sw.Write("{0}\r\n", Console.ReadLine());
sw.Flush();
}
} }
}
TcpClient