Implementing a .net proxy client in C#
Creating a proxy to another web api with Asp.net core
Table of Contents
A .NET proxy Client is an interface that lets you connect to a web service with code in .NET format. The .NET proxy can return a requested resource from its cache, or forward the request to a server that has the resource.
ProxyClient for .NET is a proxy client component targeted at the Microsoft .NET platform, which allows to easily establish proxied connections from both new and existing sockets (and TcpClient instances). As of version 2.0, it can also listen for and accept incoming connections established against a remote proxy server, as if they were accepted locally.
分为应用层代理、传输层代理和SOCKS代理
应用层代理
一种应用层上面的代理,所代理的协议是HTTP。工作在TCP/IP参考模型的应用层,支持对应用层协议(如HTTP,FTP)。常见到的Web代理
HTTP/HTTPS代理
处理Web请求
TcpListener、HttpClient
使用TcpListener监听端口,解析HTTP头部获取目标地址
通过HttpClient或WebProxy转发请求,支持SSL/TLS加密(需处理证书验证)
传输层代理。
传输层代理直接与TCP层交互,更加灵活。要求代理服务器具有部分真正服务器的功能:监听特定TCP或UDP端口,接收客户端的请求同时向客户端发出相应的响应。
SOCKS代理
代理需要改变客户端的IP栈。SOCK V4允许代理服务器内部的客户端完全地连接到外部的服务器,SOCK V5增加了对客户端的授权和认证,因此它是一种安全性较高的代理。
通用TCP/UDP转发
SOCKS握手协议、NetworkStream
支持TCP/UDP流量转发,协议无关性(如SOCKS4/5)
Proxy Protocols
代理协议的种类
ProxyClient for .NET supports the following proxy protocols:
SOCKS v4
SOCKS v4a
SOCKS v5
HTTP-CONNECT proxy
HTTPs-CONNECT proxy
代理协议包括:
http,https,websocket,tcp,udp,socks5
Modes
ProcessMode - Use Netfilter driver to intercept process traffic
ShareMode - Share your network based on WinPcap / Npcap
TunMode - Use WinTUN driver to create virtual adapter
WebMode - Web proxy mode
劫持本机流量
1.监听系统流量(修改注册表或网卡设置)
修改注册表启用系统代理(InternetSetOptionAPI)
监听本地端口(如8080)
操作系统级代理设置-修改操作系统代理设置
在程序中自动设置代理服务器,不需要用户手动进行设置的方法。实现Windows全局代理服务器的设置
R可修改本地局域网连接的代理设置,使其指向程序在本地主机上监听的端口。
可修改所有系统连接的代理设置,使其指向程序在本地主机上侦听的端口。
可修改系统中与ftp相关联的代理设置,使其指向程序在本地主机上侦听的端口。
可修改当前使用PAC文件配置方式进行网络连接时所使用到的代理设置。
应用程序级代理设置
浏览器代理设置-让用户设置代理服务器
设置IE的代理
git 代理设置
git 支持设置 http 代理和 socks5 代理,http 的代理和 https 的代理是分开设置的
search c# 实现Windows全局代理服务器的设置
search Global Windows Proxy using C# .NET
ProxyClient for .NET offers an easy way to traverse f, using proxy servers, from within your applications; it can quickly make outgoing TCP connections to SOCKS v4, SOCKS v4A, SOCKS v5 and HTTP-CONNECT proxy servers
// 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();
// ...
}
source:https://cobisi.com/proxy-client/.net-component
代理库
C# ProxyServer还有很多优点:
支持HTTP、HTTPS、SOCKS4、SOCKS5等主流代理协议
Install-Package ProxyServer
blog
web代理
https://blog.csdn.net/biyusr/article/details/145074739
C#实现Web代理服务程序(using System.Net.Sockets 实现web代理)
https://www.cnblogs.com/anlaoliu/p/7269013.html