C#代理网络通信控件支持SOCKS4/5 — ProxyClient for .NET

  • A+
所属分类:源码

ProxyClient for .NET是一个针对Microsoft .NET平台的代理客户端组件,它允许从新的和现有的套接字(以及TcpClient实例)轻松建立代理连接。支持2.0-4.5的所有版本,它还可以侦听和接受针对远程代理服务器建立的传入连接,就像它们在本地被接受一样。
示例代码

// Set up a new proxy client object, bound to a SOCKS 5 server

var proxy = new Socks5Client(IPAddress.Parse("10.0.1.2"),
"john",
"$ecrEt");

// The target endpoint will be one of the Google's webservers

var googleAddress = Dns.GetHostEntry("www.google.com").AddressList[0];
var targetEndPoint = new IPEndPoint(googleAddress, 80);

// Connect to a target IP endpoint via HTTP through a proxied connection

var proxiedConnection = proxyClient.Connect(targetEndPoint);

using (var proxiedStream = new NetworkStream(proxiedConnection.Socket))
using (var writer = new StreamWriter(proxiedStream, Encoding.ASCII))
{
// Send the HTTP request to www.google.com

writer.WriteLine("GET / HTTP/1.1");
writer.WriteLine();
writer.Flush();

// ...
}

// Set up a new proxy client object, bound to a SOCKS 5 server

var proxy = new Socks5Client(IPAddress.Parse("10.0.1.2"),
"john",
"$ecrEt");

Task.Run(async () =>
{
// Binds the remote socket to the remote HTTP port

var listeningSocket = await proxy.BindAsync(new IPv4EndPoint
{
Address = IPAddress.Any,
Port = 80 // The protocol does not guarantee to obey this
});

Console.WriteLine("Remote socket listening on: {0}",
listeningSocket.ListeningEndPoint);

// Accepts a remote connection

var acceptedSocket = await proxy.AcceptAsync(listeningSocket);

Console.WriteLine("Accepted a connection from: {0}",
acceptedSocket.RemoteEndPoint);

// Writes a message back, using the HTTP protocol

using (var proxiedStream = new NetworkStream(acceptedSocket.Socket))
using (var reader = new StreamReader(proxiedStream, Encoding.ASCII))
using (var writer = new StreamWriter(proxiedStream, Encoding.ASCII))
{
// TODO: Handle the request

while (reader.EndOfStream)
reader.ReadLine();

// Generates a useful reply

writer.WriteLine("HTTP/1.0 200 OK");
writer.WriteLine("Content-Type: text/plain");
writer.WriteLine();
writer.WriteLine("hello, world");
writer.Flush();
}

// Close the underlying socket connection

listeningSocket.Socket.Close();
});

官网地址:官网

下载地址:https://AllRes.ctfile.com/dir/4028457-28708812-c396ba/

使用时在软件启动时验证注册信息:

LicensingManager.SetLicenseKey("注册码");

特别信息:

此处为隐藏的内容!
登录后才能查看!

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: