可能重复:
如何在 C# 中创建一个简单的代理?
我正在编写一个代理应用程序,我想处理所有网络连接。我已经编写了服务器和客户端应用程序,所以现在我只需要将网络连接重定向到它。
我搜索了很多,这就是我发现的:
//For sniffing the socket to capture the packets has to be a raw socket, with the
//address family being of type internetwork, and protocol being IP
mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
//Bind the socket to the selected IP address
mainSocket.Bind(new IPEndPoint(IPAddress.Parse(cmbInterfaces.Text), 0));
//Set the socket options
mainSocket.SetSocketOption(SocketOptionLevel.IP, //Applies only to IP packets
SocketOptionName.HeaderIncluded, //Set the include the header
true); //option to true
byte[] byTrue = new byte[4] {1, 0, 0, 0};
byte[] byOut = new byte[4]{1, 0, 0, 0}; //Capture outgoing packets
我不确定这是否对我有帮助,因为我无法取消原始请求。最简单的方法是什么?