如何实现类似火狐那样的socks5代{过}{滤}理上网
我想请问一下各位哥哥姐姐如何用C#实现类似火狐这样的socks5代{过}{滤}理上网呢?我在网上看到的代码都是实现sock5服务器转发后返回代{过}{滤}理请求数据的,没找到类似火狐代{过}{滤}理这种功能的代码
ppgjx 发表于 2023-3-5 18:12
用c#实现socket协议就行
using System;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
public class Sample
{
public static string DoSocketGet(string server)
{
//Set up variables and String to write to the server.
Encoding ASCII = Encoding.ASCII;
string Get = "GET / HTTP/1.1\r\nHost: " + server +
"\r\nConnection: Close\r\n\r\n";
Byte[] ByteGet = ASCII.GetBytes(Get);
Byte[] RecvBytes = new Byte;
String strRetPage = null;
// IPAddress and IPEndPoint represent the endpoint that will
// receive the request.
// Get first IPAddress in list return by DNS.
try
{
// Define those variables to be evaluated in the next for loop and
// then used to connect to the server. These variables are defined
// outside the for loop to make them accessible there after.
Socket s = null;
IPEndPoint hostEndPoint;
IPAddress hostAddress = null;
int conPort = 80;
// Get DNS host information.
IPHostEntry hostInfo = Dns.GetHostEntry(server);
// Get the DNS IP addresses associated with the host.
IPAddress[] IPaddresses = hostInfo.AddressList;
// Evaluate the socket and receiving host IPAddress and IPEndPoint.
for (int index=0; index<IPaddresses.Length; index++)
{
hostAddress = IPaddresses;
hostEndPoint = new IPEndPoint(hostAddress, conPort);
// Creates the Socket to send data over a TCP connection.
s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
// Connect to the host using its IPEndPoint.
s.Connect(hostEndPoint);
if (!s.Connected)
{
// Connection failed, try next IPaddress.
strRetPage = "Unable to connect to host";
s = null;
continue;
}
// Sent the GET request to the host.
s.Send(ByteGet, ByteGet.Length, 0);
} // End of the for loop.
// Receive the host home page content and loop until all the data is received.
Int32 bytes = s.Receive(RecvBytes, RecvBytes.Length, 0);
strRetPage = "Default HTML page on " + server + ":\r\n";
strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0, bytes);
while (bytes > 0)
{
bytes = s.Receive(RecvBytes, RecvBytes.Length, 0);
strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0, bytes);
}
} // End of the try block.
catch(SocketException e)
{
Console.WriteLine("SocketException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
catch(ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
catch(NullReferenceException e)
{
Console.WriteLine("NullReferenceException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
catch(Exception e)
{
Console.WriteLine("Exception caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
return strRetPage;
}
public static void Main()
{
Console.WriteLine(DoSocketGet("localhost"));
}
}
这样的吗?这个只能实现转发,我想实现类似全局代{过}{滤}理上网 本帖最后由 pjy612 于 2023-3-6 00:08 编辑
你如果想实现 在C#里面 用Http访问时 想 走现成的 Socks5 的 代{过}{滤}理。 那就试试用 https://github.com/nickolasKrayn/Extreme.Net
如果 你是想自己用C#写个Socks5 服务端 那就再去找对应的资料。
如果 你是想弄个 中转层。那就去 找 端口转发 或 网络拦截 的资料。 用c#实现socket协议就行 V2不就可以了 搭建一下就行
马化腾· 发表于 2023-3-5 18:14
V2不就可以了 搭建一下就行
我是想重新开一个 Panel 发表于 2023-3-5 18:15
using System;
using System.Text;
using System.IO;
火狐也不是全局啊 只是浏览器能用 如果你要全局只能调用系统的代{过}{滤}理api用 ppgjx 发表于 2023-3-5 18:16
火狐也不是全局啊 只是浏览器能用 如果你要全局只能调用系统的代{过}{滤}理api用
对,就只要实现浏览器就行,我给出的代码就只能实现指定网址转发返回转发数据,而不能类似火狐这种代{过}{滤}理 Panel 发表于 2023-3-5 18:21
对,就只要实现浏览器就行,我给出的代码就只能实现指定网址转发返回转发数据,而不能类似火狐这种代{过} ...
你是想实现功能呢,还是想自己写代码实现功能呢? zbr878458173 发表于 2023-3-5 18:36
你是想实现功能呢,还是想自己写代码实现功能呢?
就是实现这个功能的代码 学习了,共同进步
页:
[1]
2