-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
790 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using TqkLibrary.Proxy.Interfaces; | ||
using TqkLibrary.Proxy.ProxyServers; | ||
using TqkLibrary.Proxy.ProxySources; | ||
|
||
namespace ConsoleTest | ||
{ | ||
internal static class RealTest | ||
{ | ||
const string address = "127.0.0.1:13566"; | ||
public static void HttpProxyServerTest() | ||
{ | ||
//IProxySource proxySource = new LocalProxySource(); | ||
//IProxySource proxySource = new HttpProxySource(new Uri("http://103.178.231.186:10003")); | ||
IProxySource proxySource = new HttpProxySource(new Uri("http://svhn1.proxyno1.com:41352")); | ||
HttpProxyServer httpProxyServer = new HttpProxyServer(IPEndPoint.Parse(address), proxySource); | ||
httpProxyServer.StartListen(); | ||
Console.WriteLine("server started"); | ||
Console.ReadLine(); | ||
httpProxyServer.ChangeSource(new HttpProxySource(new Uri("http://103.178.231.186:10003")), true); | ||
Console.ReadLine(); | ||
httpProxyServer.StopListen(); | ||
Console.ReadLine(); | ||
} | ||
|
||
const string address2 = "117.2.46.2:5678"; | ||
public static void Socks4ProxySourceTest() | ||
{ | ||
//IProxySource proxySource = new LocalProxySource(); | ||
//IProxySource proxySource = new HttpProxySource(new Uri("http://103.178.231.186:10003")); | ||
|
||
|
||
//IProxySource proxySource = new HttpProxySource(new Uri("http://svhn1.proxyno1.com:41352"),new NetworkCredential("user","pass")); | ||
//HttpProxyServer httpProxyServer = new HttpProxyServer(IPEndPoint.Parse("127.0.0.1:13566"), proxySource); | ||
//httpProxyServer.StartListen(); | ||
|
||
//Console.WriteLine("server started"); | ||
//Console.ReadLine(); | ||
//httpProxyServer.ChangeSource(new HttpProxySource(new Uri("http://103.178.231.186:10003")), true); | ||
//Console.ReadLine(); | ||
//httpProxyServer.StopListen(); | ||
//Console.ReadLine(); | ||
|
||
|
||
|
||
IProxySource proxySource = new Socks4ProxySource(IPEndPoint.Parse("212.213.132.5:31632"));//địa chỉ sock4 | ||
HttpProxyServer httpProxyServer = new HttpProxyServer(IPEndPoint.Parse("127.0.0.1:13566"), proxySource);//địa chỉ http proxy host lại | ||
|
||
httpProxyServer.StartListen();//xài | ||
|
||
//code..... dùng proxy 127.0.0.1:13566 | ||
|
||
httpProxyServer.StopListen();//xài xong nhớ tắt | ||
|
||
|
||
Console.ReadLine(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
TestProxy/Socks4ProxyServerTest/LocalProxySourceTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using TqkLibrary.Proxy.Interfaces; | ||
using TqkLibrary.Proxy.ProxySources; | ||
using TqkLibrary.Proxy.ProxyServers; | ||
using Newtonsoft.Json; | ||
|
||
namespace TestProxy.Socks4ProxyServerTest | ||
{ | ||
[TestClass] | ||
public class LocalProxySourceTest | ||
{ | ||
static readonly IProxySource localProxySource; | ||
|
||
static readonly SocketsHttpHandler httpClientHandler; | ||
static readonly HttpClient httpClient; | ||
static LocalProxySourceTest() | ||
{ | ||
localProxySource = new LocalProxySource(); | ||
//.Net6 support socks4 and socks5 | ||
//https://devblogs.microsoft.com/dotnet/dotnet-6-networking-improvements/#socks-proxy-support | ||
httpClientHandler = new SocketsHttpHandler() | ||
{ | ||
Proxy = new WebProxy() | ||
{ | ||
Address = new Uri($"socks4://{Singleton.Address0}"), | ||
}, | ||
UseCookies = false, | ||
UseProxy = true, | ||
}; | ||
httpClient = new HttpClient(httpClientHandler, false); | ||
} | ||
|
||
[TestMethod] | ||
public async Task HttpGet() | ||
{ | ||
using var socks4ProxyServer = new Socks4ProxyServer(IPEndPoint.Parse(Singleton.Address0), localProxySource); | ||
socks4ProxyServer.StartListen(); | ||
|
||
using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://httpbin.org/get"); | ||
using HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseHeadersRead); | ||
string content = await httpResponseMessage.Content.ReadAsStringAsync(); | ||
dynamic json = JsonConvert.DeserializeObject(content); | ||
Assert.AreEqual(json["url"]?.ToString(), "http://httpbin.org/get"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task HttpGetTwoTimes() | ||
{ | ||
using var socks4ProxyServer = new Socks4ProxyServer(IPEndPoint.Parse(Singleton.Address0), localProxySource); | ||
socks4ProxyServer.StartListen(); | ||
|
||
{ | ||
using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://httpbin.org/get"); | ||
using HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseHeadersRead); | ||
string content = await httpResponseMessage.Content.ReadAsStringAsync(); | ||
dynamic json = JsonConvert.DeserializeObject(content); | ||
Assert.AreEqual(json["url"]?.ToString(), "http://httpbin.org/get"); | ||
} | ||
|
||
//Test make new request on 1 connection with proxy | ||
{ | ||
//github will redirect (301) http -> https -> new connection proxy using CONNECT method | ||
using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://tqk2811.github.io/TqkLibrary.Proxy/Test.txt"); | ||
using HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseHeadersRead); | ||
string content = await httpResponseMessage.Content.ReadAsStringAsync(); | ||
Assert.AreEqual(content, "TqkLibrary.Proxy data"); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public async Task HttpPost() | ||
{ | ||
using var socks4ProxyServer = new Socks4ProxyServer(IPEndPoint.Parse(Singleton.Address0), localProxySource); | ||
socks4ProxyServer.StartListen(); | ||
|
||
using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "http://httpbin.org/post"); | ||
httpRequestMessage.Headers.Add("Accept", "application/json"); | ||
httpRequestMessage.Content = new StringContent("Test post"); | ||
using HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseHeadersRead); | ||
string content = await httpResponseMessage.Content.ReadAsStringAsync(); | ||
dynamic json = JsonConvert.DeserializeObject(content); | ||
Assert.AreEqual(json["url"]?.ToString(), "http://httpbin.org/post"); | ||
Assert.AreEqual(json["data"]?.ToString(), "Test post"); | ||
} | ||
|
||
|
||
[TestMethod] | ||
public async Task HttpsGet() | ||
{ | ||
using var socks4ProxyServer = new Socks4ProxyServer(IPEndPoint.Parse(Singleton.Address0), localProxySource); | ||
socks4ProxyServer.StartListen(); | ||
|
||
using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "https://httpbin.org/get"); | ||
using HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseHeadersRead); | ||
string content = await httpResponseMessage.Content.ReadAsStringAsync(); | ||
dynamic json = JsonConvert.DeserializeObject(content); | ||
Assert.AreEqual(json["url"]?.ToString(), "https://httpbin.org/get"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task HttpsPost() | ||
{ | ||
using var socks4ProxyServer = new Socks4ProxyServer(IPEndPoint.Parse(Singleton.Address0), localProxySource); | ||
socks4ProxyServer.StartListen(); | ||
|
||
using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "https://httpbin.org/post"); | ||
httpRequestMessage.Headers.Add("Accept", "application/json"); | ||
httpRequestMessage.Content = new StringContent("Test post"); | ||
using HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseHeadersRead); | ||
string content = await httpResponseMessage.Content.ReadAsStringAsync(); | ||
dynamic json = JsonConvert.DeserializeObject(content); | ||
Assert.AreEqual(json["url"]?.ToString(), "https://httpbin.org/post"); | ||
Assert.AreEqual(json["data"]?.ToString(), "Test post"); | ||
} | ||
} | ||
} |
Oops, something went wrong.