From 8dae0c0aed0451da297dcdb2e953e6b17639283f Mon Sep 17 00:00:00 2001 From: moux23333 <110985481+moux23333@users.noreply.github.com> Date: Sun, 28 Jan 2024 11:56:32 +0800 Subject: [PATCH] add other proxy detection for proxy --- FreeSR.Tool.Proxy/Program.cs | 45 ++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/FreeSR.Tool.Proxy/Program.cs b/FreeSR.Tool.Proxy/Program.cs index 62c42e6..df41d4d 100644 --- a/FreeSR.Tool.Proxy/Program.cs +++ b/FreeSR.Tool.Proxy/Program.cs @@ -1,4 +1,6 @@ -namespace FreeSR.Tool.Proxy +using System.Net; + +namespace FreeSR.Tool.Proxy { internal static class Program { @@ -6,10 +8,11 @@ private static ProxyService s_proxyService; private static EventHandler s_processExitHandler = new EventHandler(OnProcessExit); - + private static void Main(string[] args) { Console.Title = Title; + CheckProxy(); s_proxyService = new ProxyService("127.0.0.1", 8888); AppDomain.CurrentDomain.ProcessExit += s_processExitHandler; @@ -21,5 +24,43 @@ { s_proxyService.Shutdown(); } + + public static void CheckProxy() + { + try + { + string ProxyInfo = GetProxyInfo(); + if (ProxyInfo != null) + { + Console.WriteLine("well... It seems you are using other proxy software(such as Clash,V2RayN,Fiddler,etc)"); + Console.WriteLine($"You system proxy: {ProxyInfo}"); + Console.WriteLine("You have to close all other proxy software to make sure FreeSR.Tool.Proxy can work well."); + Console.WriteLine("Press any key to continue if you closed other proxy software, or you think you are not using other proxy."); + Console.ReadKey(); + } + } + catch (NullReferenceException) + { + + } + } + + public static string GetProxyInfo() + { + try + { + IWebProxy proxy = WebRequest.GetSystemWebProxy(); + Uri proxyUri = proxy.GetProxy(new Uri("https://www.example.com")); + + string proxyIP = proxyUri.Host; + int proxyPort = proxyUri.Port; + string info = proxyIP + ":" + proxyPort; + return info; + } + catch + { + return null; + } + } } } \ No newline at end of file