Giter VIP home page Giter VIP logo

httptosocks5proxy's Introduction

Stand With Ukraine

HttpToSocks5Proxy

As of .NET 6, SocketsHttpHandler supports connecting to Socks4, Socks4a and Socks5 proxies!

This project is now archived and no longer maintained. You can use this library on older versions of .NET. See the archived branch.

var client = new HttpClient(new SocketsHttpHandler()
{
    Proxy = new WebProxy("socks5://127.0.0.1:9050")
});

var content = await client.GetStringAsync("https://check.torproject.org/");
Console.WriteLine(content);

httptosocks5proxy's People

Contributors

mihazupan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

httptosocks5proxy's Issues

connection does not dispose properly

Hello.
I have been using this library in order to send my http request over Socks5. I'm using Httpwebrequest. but after a while my server throw this exeption and drop all conections:

System.Net.Sockets.SocketException (0x80004005): An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full
   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Bind(EndPoint localEP)
   at MihaZupan.HttpToSocks5Proxy..ctor(ProxyInfo[] proxyList, Int32 internalServerPort)

Unhandled Exception

Several times a day there is an exception that does not affect the work, but apparently something goes wrong

22:45:05.238|Error  |Unhandled Exception|System.AggregateException: При ожидании задачи или доступе к ее свойству исключения не были замечены исключения задачи. В результате незамеченные исключения были созданы повторно потоком завершения. ---> System.Net.Sockets.SocketException: Операция блокирования прервана вызовом WSACancelBlockingCall
   в System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   в MihaZupan.HttpToSocks5Proxy.<>c__DisplayClass23_0.<RelayData>b__0()
   в System.Threading.Tasks.Task.InnerInvoke()
   в System.Threading.Tasks.Task.Execute()
   --- Конец трассировки внутреннего стека исключений ---
---> (Внутреннее исключение #0) System.Net.Sockets.SocketException (0x80004005): Операция блокирования прервана вызовом WSACancelBlockingCall
   в System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   в MihaZupan.HttpToSocks5Proxy.<>c__DisplayClass23_0.<RelayData>b__0()
   в System.Threading.Tasks.Task.InnerInvoke()
   в System.Threading.Tasks.Task.Execute()<---

Losing query part of URI

In HttpToSocks5Proxy.cs, line 245-253 you load the full URI but extract only the path, so an URL like /foo?bar=1#today is stripped of both the query part (?bar=1) and fragment (#today). Both of these should be preserved if they're non-empty.

Cpu high

Hello sir
But today, I found this lib make cpu high when I'm using with bitvise c#, I don't know why..
when using 1 thread, it make 30% cpu and continue increase

Change Credentials Without Creating New Proxy Instance?

Hello, I'd like to be able to change the credentials (username/password) at a somewhat high frequency (once every couple seconds per proxy, across ~100 different proxy instances) without having to create a new proxy instance every time. The remote proxy IP/port will remain the same, just the credentials need to change.

Creating a new proxy instance as this frequency just to change credentials often results in the port exhaustion issues that other issues have described, even if I call StopInternalServer() on the proxy instance before creating a new one. StopInternalServer helps, but some ports do appear to get stuck open and accumulate and it quickly becomes problematic at this frequency.

Is this functionality to change credentials only supported, and if not can it be? I haven't seen an easy way to change the credentials without creating an entirely new proxy instance which has the local port exhaustion problems. I realize changing credentials requires re-authenticating to the remote socks server which is maybe why it's not currently supported.

Reason: some (very popular) proxy servers establish a new route to the URL/destination on their end if you change your credentials - so this is a easy method to rotate the remote route.

Ports exhaustion

var proxy = new HttpToSocks5Proxy("127.0.0.1", Port);
causes
An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full after a while.
Every time a new port opens and never closes. See screen:
image

Am I supposed to close something?

Infinite? Loop possible with "improved" relaying logic

In case it makes any difference: I am using v1.2.0. I am using several different HttpClients in the same process, and each of them are accessed by many threads. Each HttpClient has its own HttpToSocks5Proxy instance. I am using the latest .net core 3 preview (3.0.100 - preview 6).

After a while of running and making many (hundreds) of requests, all available CPU will start being consumed. It appears this is due to an infinite/very large recursive loop in the code added in 7632534. The call stack looks like:

>	System.Net.Sockets.dll!System.Net.Sockets.SocketAsyncEventArgs.DoOperationSendSingleBuffer(System.Net.Sockets.SafeSocketHandle handle, System.Threading.CancellationToken cancellationToken) Line 607	C#
 	System.Net.Sockets.dll!System.Net.Sockets.Socket.SendAsync(System.Net.Sockets.SocketAsyncEventArgs e, System.Threading.CancellationToken cancellationToken) Line 4216	C#
 	MihaZupan.HttpToSocks5Proxy.dll!MihaZupan.SocketRelay.OnReceived()	Unknown
 	MihaZupan.HttpToSocks5Proxy.dll!MihaZupan.SocketRelay.StartRelaying()	Unknown
 	MihaZupan.HttpToSocks5Proxy.dll!MihaZupan.SocketRelay.OnSent()	Unknown
 	MihaZupan.HttpToSocks5Proxy.dll!MihaZupan.SocketRelay.OnReceived()	Unknown
 	MihaZupan.HttpToSocks5Proxy.dll!MihaZupan.SocketRelay.StartRelaying()	Unknown
 	MihaZupan.HttpToSocks5Proxy.dll!MihaZupan.SocketRelay.OnSent()	Unknown
	[... several hundred lines ...]
 	MihaZupan.HttpToSocks5Proxy.dll!MihaZupan.SocketRelay.StartRelaying()	Unknown
 	MihaZupan.HttpToSocks5Proxy.dll!MihaZupan.SocketRelay.OnSent()	Unknown
 	MihaZupan.HttpToSocks5Proxy.dll!MihaZupan.SocketRelay.OnReceived()	Unknown
 	MihaZupan.HttpToSocks5Proxy.dll!MihaZupan.SocketRelay.StartRelaying()	Unknown
 	MihaZupan.HttpToSocks5Proxy.dll!MihaZupan.SocketRelay.OnSent()	Unknown
 	MihaZupan.HttpToSocks5Proxy.dll!MihaZupan.SocketRelay.OnReceived()	Unknown
 	MihaZupan.HttpToSocks5Proxy.dll!MihaZupan.SocketRelay.StartRelaying()	Unknown
 	MihaZupan.HttpToSocks5Proxy.dll!MihaZupan.SocketRelay.OnSent()	Unknown
 	MihaZupan.HttpToSocks5Proxy.dll!MihaZupan.SocketRelay.OnReceived()	Unknown
 	MihaZupan.HttpToSocks5Proxy.dll!MihaZupan.SocketRelay.StartRelaying()	Unknown
 	System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread threadPoolThread, System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 289	C#
 	System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot, System.Threading.Thread threadPoolThread) Line 2406	C#
 	System.Private.CoreLib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() Line 663	C#

I wasn't having any problems with 1.1.3 so I'll probably just downgrade to the time being.

Does anybody have the same problem? "Could not create SSL/TLS secure channel"

I'm using HttpToSocks5Proxy with TelegramBotClient. A day ago I got an "Could not create SSL/TLS secure channel" error. My code used to sent messages, but now it don't.

I found out that, due to Telegram disabling everything older than TLS v1.2 (which is not used as the default in .NET Framework 4.5 and earlier)
TelegramBots/Telegram.Bot#867
TelegramBots/Telegram.Bot#869

I tried all the proposed solutions in the tickets above, but nothing helped.
I tried to add line above to HttpToSocks5Proxy.cs, but it didn't work for me
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

Any ideas how to fix the problem? Thank you in advance!

OnAcceptCallback throw unhandled exception

I tried throw exception inside the OnAcceptCallback method (HttpToSocks5Proxy class 101), the error always occurs, but cannot be processed inside the try catch block ..

Create an error :
Edit the method OnAcceptCallback throw new exception ("test);
Run test

IWebProxy webproxy = new HttpToSocks5Proxy ("127.0.0.1", 5789);
Webclient webclient = new Webclient ();
webclient.Proxy = webproxy;

try {
webclient.DownloadString("https://google.com");
}
catch(Exception e)
{
Console.Write("error");
//Don't throw bugs here
}

Adding headers doesn't work

query http://headers.jsontest.com/ and don't get any headers back

var proxy = new HttpToSocks5Proxy("127.0.0.1", Port);
var handler = new HttpClientHandler { Proxy = proxy };
var httpClient = new System.Net.Http.HttpClient(handler, true);
httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.3611");
var httpsGet = httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, "http://headers.jsontest.com/"));
var str = httpsGet.Result.Content.ReadAsStringAsync().Result;
return str;

result is

{
   "X-Cloud-Trace-Context": "d8c6980d837ac0a57f8189571defbvg4432979",
   "Host": "headers.jsontest.com"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.