From 16ed946376d2bca379405850bfd3ca92aec3f349 Mon Sep 17 00:00:00 2001 From: goingfine Date: Tue, 25 Apr 2023 13:08:21 +0330 Subject: [PATCH 1/5] added UPLOAD testing feature --- windows/Classes/Checker/AbstractChecker.cs | 71 ++++ .../Classes/{ => Checker}/CheckIPWorking.cs | 145 ++++--- windows/Classes/Checker/CheckResultStatus.cs | 45 +++ windows/Classes/Checker/CheckSettings.cs | 30 ++ windows/Classes/Checker/DownloadChecker.cs | 55 +++ windows/Classes/Checker/UploadChecker.cs | 62 +++ windows/Classes/Config/AppConfig.cs | 5 +- windows/Classes/Config/ScanResults.cs | 54 ++- windows/Classes/ScanEngine.cs | 22 +- windows/Classes/ScanProgressInfo.cs | 2 +- windows/frmMain.Designer.cs | 370 ++++++++++-------- windows/frmMain.cs | 87 ++-- windows/frmMain.resx | 11 +- 13 files changed, 665 insertions(+), 294 deletions(-) create mode 100644 windows/Classes/Checker/AbstractChecker.cs rename windows/Classes/{ => Checker}/CheckIPWorking.cs (68%) create mode 100644 windows/Classes/Checker/CheckResultStatus.cs create mode 100644 windows/Classes/Checker/CheckSettings.cs create mode 100644 windows/Classes/Checker/DownloadChecker.cs create mode 100644 windows/Classes/Checker/UploadChecker.cs diff --git a/windows/Classes/Checker/AbstractChecker.cs b/windows/Classes/Checker/AbstractChecker.cs new file mode 100644 index 00000000..670c776e --- /dev/null +++ b/windows/Classes/Checker/AbstractChecker.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace WinCFScan.Classes.Checker +{ + internal abstract class AbstractChecker + { + public HttpClient client; + public CheckSettings checkSettings { get; } + public CheckSettings cs { get; } // abbreviated of above checkSettings + public string exceptionMessage = ""; + public long checkDuration; + + + public AbstractChecker(CheckSettings checkSettings) + { + this.checkSettings = cs = checkSettings; + + var proxy = new WebProxy(); + proxy.Address = new Uri($"socks5://127.0.0.1:{cs.port}"); + var handler = new HttpClientHandler + { + Proxy = proxy + }; + + this.client = new HttpClient(handler); + this.client.Timeout = TimeSpan.FromSeconds(cs.timeout); + } + + public abstract bool check(); + + protected void handleException(Exception ex) + { + string message = ex.Message; + if (isTimeoutException(ex)) + { + Tools.logStep($"{checkSettings.checkType} timed out.", cs.isDiagnosing); + } + else + { + Tools.logStep($"{checkSettings.checkType} had exception: {message}", cs.isDiagnosing); + + exceptionMessage = message; + + if (ex.InnerException != null && ex.InnerException?.Message != "" && !ex.Message.Contains(ex.InnerException?.Message)) + { + Tools.logStep($"Inner exception: {ex.InnerException?.Message}", cs.isDiagnosing); + } + } + } + + private bool isTimeoutException(Exception ex) + { + string msg = ex.Message; + return msg.Contains("The request was aborted") || + msg.Contains("A task was canceled."); + } + } + + public enum CheckType + { + DOWNLOAD, + UPLOAD, + BOTH + } + +} diff --git a/windows/Classes/CheckIPWorking.cs b/windows/Classes/Checker/CheckIPWorking.cs similarity index 68% rename from windows/Classes/CheckIPWorking.cs rename to windows/Classes/Checker/CheckIPWorking.cs index d7860b92..1cac8f62 100644 --- a/windows/Classes/CheckIPWorking.cs +++ b/windows/Classes/Checker/CheckIPWorking.cs @@ -10,46 +10,52 @@ using WinCFScan.Classes.Config; using WinCFScan.Classes.HTTPRequest; -namespace WinCFScan.Classes +namespace WinCFScan.Classes.Checker { internal class CheckIPWorking { private readonly string ip; - private Process? process ; + private Process? process; private string port; private string v2rayConfigPath; public long downloadDuration { get; private set; } + public long uploadDuration { get; private set; } public long frontingDuration { get; private set; } - private ScanSpeed targetSpeed; + private ScanSpeed dlTargetSpeed; + private ScanSpeed upTargetSpeed; private readonly CustomConfigInfo scanConfig; - private readonly int downloadTimeout; + private readonly int checkTimeout; public string downloadException = ""; + public string uploadException = ""; public string frontingException = ""; private bool isDiagnosing = false; public bool isV2rayExecutionSuccess = false; + public CheckType checkType { get; private set; } + private CheckResultStatus checkResultStatus; - - - public CheckIPWorking(string ip, ScanSpeed targetSpeed, CustomConfigInfo scanConfig, int downloadTimeout, bool isDiagnosing = false) + public CheckIPWorking(string ip, ScanSpeed dlTargetSpeed, ScanSpeed upTargetSpeed, CustomConfigInfo scanConfig, CheckType checkType, int checkTimeout, bool isDiagnosing = false) { this.ip = ip; - this.port = getPortByIP(); + port = getPortByIP(); v2rayConfigPath = $"v2ray-config/generated/config.{ip}.json"; - this.targetSpeed = targetSpeed; + this.dlTargetSpeed = dlTargetSpeed; + this.upTargetSpeed = upTargetSpeed; this.scanConfig = scanConfig; - this.downloadTimeout = downloadTimeout; + this.checkTimeout = checkTimeout; this.isDiagnosing = isDiagnosing; + this.checkType = checkType; + checkResultStatus = new CheckResultStatus(checkType); } public CheckIPWorking() { } - public bool check() + public bool check() { bool v2rayDLSuccess = false; Tools.logStep("\n------------ Start IP Check ------------", isDiagnosing); - Tools.logStep("IP: " + this.ip, isDiagnosing); + Tools.logStep("IP: " + ip, isDiagnosing); // first of all quick test on fronting domain through cloudflare bool frontingSuccess = checkFronting(); @@ -57,7 +63,7 @@ public bool check() if (frontingSuccess || isDiagnosing) // on diagnosing we will always test v2ray { // don't speed test if that mode is selected by user - if (targetSpeed.isSpeedZero() && !isDiagnosing) + if (dlTargetSpeed.isSpeedZero() && !isDiagnosing) { v2rayDLSuccess = true; } @@ -70,7 +76,7 @@ public bool check() } Tools.logStep( - string.Format(Environment.NewLine + "Fronting Result: {0}", frontingSuccess ? "SUCCESS" : "FAILED") + Environment.NewLine + + string.Format(Environment.NewLine + "Fronting Result: {0}", frontingSuccess ? "SUCCESS" : "FAILED") + Environment.NewLine + string.Format("v2ray.exe Execution: {0}", isV2rayExecutionSuccess ? "SUCCESS" : "FAILED") + Environment.NewLine + string.Format("Download Result: {0}", v2rayDLSuccess ? "SUCCESS" : "FAILED"), isDiagnosing ); @@ -80,16 +86,18 @@ public bool check() } - public bool checkV2ray() { + public bool checkV2ray() + { bool success = false; + // create config if (createV2rayConfigFile()) { // start v2ray.exe process if (runV2rayProcess()) { - // send download request - if (checkDownloadSpeed()) + // send download/upload request + if (checkV2raySpeed()) { // speed was enough success = true; @@ -123,7 +131,7 @@ public bool checkFronting(bool withCustumDNSResolver = true, int timeout = 1) Stopwatch sw = new Stopwatch(); try { - + string frUrl = "https://" + ConfigManager.Instance.getAppConfig()?.frontDomain; Tools.logStep($"Fronting check with url: {frUrl}", isDiagnosing); sw.Start(); @@ -156,66 +164,45 @@ public bool checkFronting(bool withCustumDNSResolver = true, int timeout = 1) } - private bool checkDownloadSpeed() + private bool checkV2raySpeed() { - var proxy = new WebProxy(); - proxy.Address = new Uri($"socks5://127.0.0.1:{port}"); - var handler = new HttpClientHandler + // check download + if (checkType is CheckType.DOWNLOAD or CheckType.BOTH) { - Proxy = proxy - }; - - int timeout = this.downloadTimeout; - - var client = new HttpClient(handler); - client.Timeout = TimeSpan.FromSeconds(timeout); // 2 seconds - Tools.logStep(Environment.NewLine + "----- Download Test -----", isDiagnosing); - Tools.logStep($"Start check dl speed, proxy port: {port}, timeout: {timeout} sec, target speed: {targetSpeed.getTargetSpeed():n0} b/s", isDiagnosing); - Stopwatch sw = new Stopwatch(); - //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; - - try - { - sw.Start(); - string dlUrl = "https://" + ConfigManager.Instance.getAppConfig().scanDomain + targetSpeed.getTargetFileSize(timeout); - Tools.logStep($"Starting dl url: {dlUrl}", isDiagnosing); - var data = client.GetStringAsync(dlUrl).Result; - Tools.logStep($"*** Download success in {sw.ElapsedMilliseconds:n0} ms, dl size: {data.Length:n0} bytes for IP {ip}", isDiagnosing); - - return data.Length == targetSpeed.getTargetSpeed() * timeout; - } - catch (Exception ex) - { - string message = ex.Message; - if (isTimeoutException(ex)) + string dlUrl = "https://" + ConfigManager.Instance.getAppConfig().downloadDomain + dlTargetSpeed.getTargetFileSize(checkTimeout); + var cs = new CheckSettings(ip, port, checkTimeout, dlUrl, isDiagnosing, checkType, dlTargetSpeed); + var dlChecker = new DownloadChecker(cs); + if (dlChecker.check()) { - Tools.logStep("Download timed out.", isDiagnosing); + checkResultStatus.setDownloadSuccess(); + downloadDuration = dlChecker.checkDuration; } else { - Tools.logStep($"Download had exception: {message}", isDiagnosing); - // monitor exceptions - downloadException = message; - - if (ex.InnerException != null && ex.InnerException?.Message != "" && ! ex.Message.Contains(ex.InnerException?.Message)) - { - Tools.logStep($"Inner exception: {ex.InnerException?.Message}", isDiagnosing); - } + this.downloadException = dlChecker.exceptionMessage; } - return false; } - finally - { - downloadDuration = sw.ElapsedMilliseconds; - if(downloadDuration > (timeout * 1000) + 500) + + // check upload + if (checkType is CheckType.UPLOAD or CheckType.BOTH){ + string upUrl = "https://" + ConfigManager.Instance.getAppConfig().uploadDomain; + var cs = new CheckSettings(ip, port, checkTimeout, upUrl, isDiagnosing, checkType, upTargetSpeed); + var upChecker = new UploadChecker(cs); + if (upChecker.check()) { - Tools.logStep($"Download took too long! {downloadDuration:n0} ms for IP {ip}", isDiagnosing); + checkResultStatus.setUploadSuccess(); + uploadDuration = upChecker.checkDuration; + } + else + { + this.uploadException = upChecker.exceptionMessage; } - handler.Dispose(); - client.Dispose(); } + + return checkResultStatus.isSuccess(); } + private bool isTimeoutException(Exception ex) { string msg = ex.Message; @@ -240,7 +227,7 @@ private bool createV2rayConfigFile() .Replace("HOSTHOST", clientConfig.host) .Replace("CFPORTCFPORT", clientConfig.port) .Replace("RANDOMHOST", getRandomSNI(clientConfig.host)) - .Replace("IP.IP.IP.IP", this.ip) + .Replace("IP.IP.IP.IP", ip) .Replace("ENDPOINTENDPOINT", clientConfig.path); } else @@ -248,7 +235,7 @@ private bool createV2rayConfigFile() configTemplate = scanConfig.content; configTemplate = configTemplate .Replace("PORTPORT", port) - .Replace("IP.IP.IP.IP", this.ip); + .Replace("IP.IP.IP.IP", ip); } File.WriteAllText(v2rayConfigPath, configTemplate); @@ -267,15 +254,15 @@ private string getRandomSNI(string host) { var urlParts = host.Split("."); urlParts[0] = Guid.NewGuid().ToString(); - return string.Join(".", urlParts); + return string.Join(".", urlParts); } // sum of ip segments plus 3000 private string getPortByIP() - { - int sum = Int32.Parse( - this.ip.Split(".").Aggregate((current, next) => - (Int32.Parse(current) + Int32.Parse(next)).ToString()) + { + int sum = int.Parse( + ip.Split(".").Aggregate((current, next) => + (int.Parse(current) + int.Parse(next)).ToString()) ); return (3000 + sum).ToString(); @@ -287,10 +274,10 @@ private bool runV2rayProcess() startInfo.FileName = "v2ray.exe"; //if (!ConfigManager.Instance.enableDebug) //{ - startInfo.WindowStyle = ProcessWindowStyle.Hidden; - startInfo.RedirectStandardOutput = true; - startInfo.RedirectStandardError = true; - startInfo.CreateNoWindow = true; + startInfo.WindowStyle = ProcessWindowStyle.Hidden; + startInfo.RedirectStandardOutput = true; + startInfo.RedirectStandardError = true; + startInfo.CreateNoWindow = true; //} startInfo.UseShellExecute = false; startInfo.Arguments = $"run -config=\"{v2rayConfigPath}\""; @@ -309,7 +296,7 @@ private bool runV2rayProcess() { Tools.logStep($"v2ray.exe execution had exception: {ex.Message}", isDiagnosing); } - + // log error if (!wasSuccess) { @@ -320,7 +307,7 @@ private bool runV2rayProcess() Tools.logStep(message, isDiagnosing); downloadException = message; } - catch (Exception) {} + catch (Exception) { } } isV2rayExecutionSuccess = wasSuccess; @@ -328,6 +315,6 @@ private bool runV2rayProcess() return wasSuccess; } - + } } diff --git a/windows/Classes/Checker/CheckResultStatus.cs b/windows/Classes/Checker/CheckResultStatus.cs new file mode 100644 index 00000000..bb2d3932 --- /dev/null +++ b/windows/Classes/Checker/CheckResultStatus.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinCFScan.Classes.Checker +{ + internal class CheckResultStatus + { + private bool isDownloadSuccess = false; + private bool isUploadSuccess = false; + private CheckType checkType; + + public CheckResultStatus(CheckType scanType) + { + this.checkType = scanType; + } + + // return true or false base on check type + public bool isSuccess() + { + switch(checkType) { + default: + case CheckType.DOWNLOAD: + return isDownloadSuccess; + case CheckType.UPLOAD: + return isUploadSuccess; + case CheckType.BOTH: + return isDownloadSuccess && isUploadSuccess; + } + } + + public void setDownloadSuccess() + { + this.isDownloadSuccess = true; + } + + public void setUploadSuccess() + { + this.isUploadSuccess = true; + } + } +} diff --git a/windows/Classes/Checker/CheckSettings.cs b/windows/Classes/Checker/CheckSettings.cs new file mode 100644 index 00000000..b2a6dbcd --- /dev/null +++ b/windows/Classes/Checker/CheckSettings.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WinCFScan.Classes.Checker +{ + internal class CheckSettings + { + public readonly string ip; + public readonly string port; + public readonly int timeout; + public readonly string targetUrl; + public readonly bool isDiagnosing; + public readonly CheckType checkType; + public readonly ScanSpeed targetSpeed; + + public CheckSettings(string ip, string port, int timeout, string targetUrl, bool isDiagnosing, CheckType checkType, ScanSpeed targetSpeed) + { + this.port = port; + this.ip = ip; + this.timeout = timeout; + this.targetUrl = targetUrl; + this.isDiagnosing = isDiagnosing; + this.checkType = checkType; + this.targetSpeed = targetSpeed; + } + } +} diff --git a/windows/Classes/Checker/DownloadChecker.cs b/windows/Classes/Checker/DownloadChecker.cs new file mode 100644 index 00000000..818580a6 --- /dev/null +++ b/windows/Classes/Checker/DownloadChecker.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using WinCFScan.Classes.Config; + +namespace WinCFScan.Classes.Checker +{ + internal class DownloadChecker : AbstractChecker + { + public DownloadChecker(CheckSettings checkSettings) : base(checkSettings) + { + } + + public override bool check() + { + // note: 'cs' mean checkSettings + + Tools.logStep(Environment.NewLine + "----- Download Test -----", cs.isDiagnosing); + Tools.logStep($"Start check dl speed, proxy port: {cs.port}, timeout: {cs.timeout} sec, target speed: {cs.targetSpeed.getTargetSpeed():n0} b/s", cs.isDiagnosing); + + Stopwatch sw = new Stopwatch(); + + try + { + sw.Start(); + Tools.logStep($"Starting dl url: {cs.targetUrl}", cs.isDiagnosing); + var data = client.GetStringAsync(cs.targetUrl).Result; + + Tools.logStep($"*** Download success in {sw.ElapsedMilliseconds:n0} ms, dl size: {data.Length:n0} bytes for IP {cs.ip}", cs.isDiagnosing); + + return data.Length == cs.targetSpeed.getTargetSpeed() * cs.timeout; + } + catch (Exception ex) + { + this.handleException(ex); + + return false; + } + finally + { + checkDuration = sw.ElapsedMilliseconds; + if (checkDuration > cs.timeout * 1000 + 500) + { + Tools.logStep($"Download took too long! {checkDuration:n0} ms for IP {cs.ip}", cs.isDiagnosing); + } + + client.Dispose(); + } + } + } +} diff --git a/windows/Classes/Checker/UploadChecker.cs b/windows/Classes/Checker/UploadChecker.cs new file mode 100644 index 00000000..d82d828a --- /dev/null +++ b/windows/Classes/Checker/UploadChecker.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Security.Policy; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace WinCFScan.Classes.Checker +{ + internal class UploadChecker : AbstractChecker + { + public UploadChecker(CheckSettings checkSettings) : base(checkSettings) + { + } + + public override bool check() + { + // note: 'cs' mean checkSettings + + Tools.logStep(Environment.NewLine + "----- Upload Test -----", cs.isDiagnosing); + Tools.logStep($"Start check up speed, proxy port: {cs.port}, timeout: {cs.timeout} sec, target speed: {cs.targetSpeed.getTargetSpeed():n0} b/s", cs.isDiagnosing); + + Stopwatch sw = new Stopwatch(); + + try + { + sw.Start(); + Tools.logStep($"Starting up url: {cs.targetUrl}", cs.isDiagnosing); + + //upload + int uploadSize = cs.targetSpeed.getTargetFileSizeInt(cs.timeout); + HttpContent c = new StringContent(new string('*', uploadSize), Encoding.UTF8, "text/plain"); + var data = client.PostAsync(cs.targetUrl, c).Result; + + //string responseString = data.Content.ReadAsStringAsync().Result; + + Tools.logStep($"*** Upload success in {sw.ElapsedMilliseconds:n0} ms, upload size: {uploadSize:n0} bytes for IP {cs.ip}", cs.isDiagnosing); + + return data.IsSuccessStatusCode; + + } + catch (Exception ex) + { + this.handleException(ex); + + return false; + } + finally + { + checkDuration = sw.ElapsedMilliseconds; + if (checkDuration > cs.timeout * 1000 + 500) + { + Tools.logStep($"Upload took too long! {checkDuration:n0} ms for IP {cs.ip}", cs.isDiagnosing); + } + + client.Dispose(); + } + } + } +} diff --git a/windows/Classes/Config/AppConfig.cs b/windows/Classes/Config/AppConfig.cs index fb9e7cfc..8f0f2596 100644 --- a/windows/Classes/Config/AppConfig.cs +++ b/windows/Classes/Config/AppConfig.cs @@ -13,7 +13,8 @@ internal class AppConfig : ConfigInterface protected AppConfig? loadedInstance; public string frontDomain { get; set; } - public string scanDomain { get; set; } + public string downloadDomain { get; set; } + public string uploadDomain { get; set; } public string clientConfigUrl { get; set; } // load app config @@ -41,7 +42,7 @@ public bool load() public bool isConfigValid() { - return frontDomain != null && scanDomain != null && clientConfigUrl != null; + return frontDomain != null && downloadDomain != null && uploadDomain != null && clientConfigUrl != null; } public AppConfig? getLoadedInstance() diff --git a/windows/Classes/Config/ScanResults.cs b/windows/Classes/Config/ScanResults.cs index d857e433..91d65cf1 100644 --- a/windows/Classes/Config/ScanResults.cs +++ b/windows/Classes/Config/ScanResults.cs @@ -74,20 +74,26 @@ public bool loadPlain() } string plainString = File.ReadAllText(resultsFileName); - long delay = 0; string ip; - foreach(var line in plainString.Split("\n")) + long DLDelay = 0, UPDelay = 0; string ip; + foreach(var line in plainString.Split(Environment.NewLine)) { - ip = line; delay = 0; + ip = line; + // DL UP IP + // 1023 - 902 - 192.168.1.2 if(line.Contains(" - ")) { var splited = line.Split(" - "); - long.TryParse(splited[0], out delay); - ip = splited[1]; + if (splited.Length == 3) + { + long.TryParse(splited[0], out DLDelay); + long.TryParse(splited[1], out UPDelay); + ip = splited[2]; + } } if(IPAddressExtensions.isValidIPAddress(ip)) { - this.addIPResult(delay, ip); + this.addIPResult(DLDelay, UPDelay, ip); } } @@ -109,7 +115,7 @@ public bool save(bool sortBeforeSave = true) { if (sortBeforeSave) { - workingIPs = this.workingIPs.OrderBy(x => x.delay).ToList(); + workingIPs = this.workingIPs.OrderBy(x => x.downloadDelay).ToList(); } endDate = DateTime.Now; JsonSerializerOptions options= new JsonSerializerOptions(); @@ -134,11 +140,11 @@ public bool savePlain(bool sortBeforeSave = true) { if (sortBeforeSave) { - workingIPs = this.workingIPs.OrderBy(x => x.delay).ToList(); + workingIPs = this.workingIPs.OrderBy(x => x.downloadDelay).ToList(); } - var plain = workingIPs.Select(x => $"{x.delay} - {x.ip}").ToArray(); - File.WriteAllText(resultsFileName, String.Join("\n", plain)); + var plain = workingIPs.Select(x => $"{x.downloadDelay} - {x.uploadDelay} - {x.ip}").ToArray(); + File.WriteAllText(resultsFileName, String.Join(Environment.NewLine, plain)); } catch (Exception ex) { @@ -155,16 +161,16 @@ public bool savePlain(bool sortBeforeSave = true) return loadedInstance; } - public void addIPResult(long delay, string ip ) + public void addIPResult(long downloadDelay, long uploadDelay, string ip ) { - ResultItem resultItem = new ResultItem(delay, ip); + ResultItem resultItem = new ResultItem(downloadDelay, uploadDelay, ip, downloadDelay); workingIPs.Add(resultItem); - unFetchedWorkingIPs.Add(new ResultItem(delay, ip)); + unFetchedWorkingIPs.Add(new ResultItem(downloadDelay, uploadDelay, ip, downloadDelay)); thereIsNewWorkingIPs = true; totalFoundWorkingIPs++; totalFoundWorkingIPsCurrentRange++; totalUnsavedWorkingIPs++; - if (fastestIP == null || resultItem.delay < fastestIP.delay) + if (fastestIP == null || resultItem.downloadDelay < fastestIP.downloadDelay || resultItem.uploadDelay < fastestIP.uploadDelay) { fastestIP = resultItem; } @@ -203,13 +209,27 @@ internal void remove() internal class ResultItem { - public long delay { get; set; } + public long delay { get; set; } // keeping it only for compatibility reasons + public long downloadDelay { get; set; } + public long uploadDelay { get; set; } public string ip { get; set; } - public ResultItem(long delay = 0, string ip = "") + public ResultItem(long downloadDelay = 0, long uploadDelay = 0, string ip = "", long delay = 0) { - this.delay = delay; this.ip = ip; + + // for compatibility of old releases which only have delay field + if (delay != 0 && downloadDelay ==0 && uploadDelay == 0) + { + this.delay = delay; + this.downloadDelay = delay; + return; + } + + this.delay = downloadDelay; // remove it on future releases + this.downloadDelay = downloadDelay; + this.uploadDelay = uploadDelay; + } } } diff --git a/windows/Classes/ScanEngine.cs b/windows/Classes/ScanEngine.cs index 376cea4d..b08d929a 100644 --- a/windows/Classes/ScanEngine.cs +++ b/windows/Classes/ScanEngine.cs @@ -7,6 +7,7 @@ using System.Net; using System.Text; using System.Threading.Tasks; +using WinCFScan.Classes.Checker; using WinCFScan.Classes.Config; using WinCFScan.Classes.HTTPRequest; using WinCFScan.Classes.IP; @@ -25,11 +26,13 @@ internal class ScanEngine public List? workingIPsFromPrevScan { get; set; } public string v2rayDiagnosingMessage { get; private set; } public bool isV2rayExecutionSuccess { get; private set; } + public ScanSpeed upTargetSpeed { get; set; } + public CheckType checkType { get; set; } public int concurrentProcess = 4; - public ScanSpeed targetSpeed; + public ScanSpeed dlTargetSpeed; public CustomConfigInfo scanConfig; - public int downloadTimeout = 2; + public int checkTimeout = 2; private bool skipAfterFoundIPsEnabled; private bool skipAfterAWhileEnabled; private Stopwatch curRangeTimer; @@ -238,7 +241,7 @@ private void parallelScan(List ipRange) { progressInfo.curentWorkingThreads++; } - var checker = new CheckIPWorking(ip, targetSpeed, scanConfig, downloadTimeout, isDiagnosing); + var checker = new CheckIPWorking(ip, dlTargetSpeed, this.upTargetSpeed, scanConfig, this.checkType, checkTimeout, isDiagnosing); bool isOK = checker.check(); lock (locker) @@ -250,11 +253,11 @@ private void parallelScan(List ipRange) } //Thread.Sleep(1); - LogControl.Write($"{ip.PadRight(15)} is {isOK.ToString().PadRight(5)} front in: {checker.frontingDuration:n0} ms, dl in: {checker.downloadDuration:n0} ms"); + LogControl.Write($"{ip.PadRight(15)} is {isOK.ToString().PadRight(5)} front in: {checker.frontingDuration:n0} ms, dl in: {checker.downloadDuration:n0} ms, up in: {checker.uploadDuration:n0} ms"); if (isOK) { - progressInfo.scanResults.addIPResult(checker.downloadDuration, ip); + progressInfo.scanResults.addIPResult(checker.downloadDuration, checker.uploadDuration, ip); } setDiagnoseMessage(checker); @@ -312,9 +315,12 @@ private void monitorExceptions(CheckIPWorking checker) { // monitoring exceptions rate if (checker.downloadException != "") - progressInfo.downloadExceptions.addError(checker.downloadException); - else - progressInfo.downloadExceptions.addScuccess(); + progressInfo.downloadUploadExceptions.addError(checker.downloadException); + if (checker.uploadException != "") + progressInfo.downloadUploadExceptions.addError(checker.uploadException); + + if(checker.downloadException == "" && checker.uploadException == "") + progressInfo.downloadUploadExceptions.addScuccess(); if (checker.frontingException != "") progressInfo.frontingExceptions.addError(checker.frontingException); diff --git a/windows/Classes/ScanProgressInfo.cs b/windows/Classes/ScanProgressInfo.cs index 762f2dd6..c71e01e8 100644 --- a/windows/Classes/ScanProgressInfo.cs +++ b/windows/Classes/ScanProgressInfo.cs @@ -24,7 +24,7 @@ internal class ScanProgressInfo internal int currentIPRangeTotalIPs = 0; internal int totalCheckedIPInCurIPRange = 0; internal int totalCheckedIP = 0; - internal ExceptionMonitor downloadExceptions = new("Download Errors"); + internal ExceptionMonitor downloadUploadExceptions = new("Download Upload Errors"); internal ExceptionMonitor frontingExceptions = new("Fronting Errors"); internal int curentWorkingThreads = 0; internal ScanStatus scanStatus = ScanStatus.STOPPED; diff --git a/windows/frmMain.Designer.cs b/windows/frmMain.Designer.cs index 040da7f4..d77e259a 100644 --- a/windows/frmMain.Designer.cs +++ b/windows/frmMain.Designer.cs @@ -36,17 +36,7 @@ private void InitializeComponent() lblLastIPRange = new Label(); timerProgress = new System.Windows.Forms.Timer(components); groupBox1 = new GroupBox(); - toolStrip1 = new ToolStrip(); - btnStart = new ToolStripSplitButton(); - mnuPauseScan = new ToolStripMenuItem(); - toolStripSeparator2 = new ToolStripSeparator(); - comboConcurrent = new ToolStripComboBox(); - lblConcurrent = new ToolStripLabel(); - comboTargetSpeed = new ToolStripComboBox(); - lblTargetSpeed = new ToolStripLabel(); - comboConfigs = new ToolStripComboBox(); - toolStripLabel3 = new ToolStripLabel(); - toolStripSeparator1 = new ToolStripSeparator(); + toolStrip2 = new ToolStrip(); prgOveral = new ToolStripProgressBar(); toolStripLabel1 = new ToolStripLabel(); btnSkipCurRange = new ToolStripSplitButton(); @@ -58,6 +48,18 @@ private void InitializeComponent() mnuSkipAfter50Percent = new ToolStripMenuItem(); prgCurRange = new ToolStripProgressBar(); toolStripLabel2 = new ToolStripLabel(); + toolStrip1 = new ToolStrip(); + btnStart = new ToolStripSplitButton(); + mnuPauseScan = new ToolStripMenuItem(); + toolStripSeparator2 = new ToolStripSeparator(); + comboConcurrent = new ToolStripComboBox(); + lblConcurrent = new ToolStripLabel(); + comboCheckType = new ToolStripComboBox(); + comboUpTargetSpeed = new ToolStripComboBox(); + comboDLTargetSpeed = new ToolStripComboBox(); + lblTargetSpeed = new ToolStripLabel(); + comboConfigs = new ToolStripComboBox(); + toolStripLabel3 = new ToolStripLabel(); lblDebugMode = new Label(); btnCopyFastestIP = new Button(); txtFastestIP = new TextBox(); @@ -70,7 +72,8 @@ private void InitializeComponent() checkScanInRandomOrder = new CheckBox(); listResults = new ListView(); hdrIP = new ColumnHeader(); - hdrDelay = new ColumnHeader(); + hdrDLDelay = new ColumnHeader(); + hdrUPDelay = new ColumnHeader(); mnuListView = new ContextMenuStrip(components); mnuListViewCopyIP = new ToolStripMenuItem(); mnuTestThisIP = new ToolStripMenuItem(); @@ -138,7 +141,9 @@ private void InitializeComponent() linkBuyMeCoffee = new ToolStripLabel(); seperatorPaused = new ToolStripSeparator(); lblScanPaused = new ToolStripLabel(); + toolStripLabel4 = new ToolStripLabel(); groupBox1.SuspendLayout(); + toolStrip2.SuspendLayout(); toolStrip1.SuspendLayout(); mnuListView.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit(); @@ -166,7 +171,7 @@ private void InitializeComponent() txtLog.Name = "txtLog"; txtLog.ReadOnly = true; txtLog.ScrollBars = ScrollBars.Vertical; - txtLog.Size = new Size(860, 182); + txtLog.Size = new Size(838, 182); txtLog.TabIndex = 1; txtLog.Text = "Welcome to Cloudflare IP Scanner.\r\n"; // @@ -202,6 +207,7 @@ private void InitializeComponent() // groupBox1 // groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + groupBox1.Controls.Add(toolStrip2); groupBox1.Controls.Add(toolStrip1); groupBox1.Controls.Add(lblDebugMode); groupBox1.Controls.Add(btnCopyFastestIP); @@ -212,21 +218,125 @@ private void InitializeComponent() groupBox1.Location = new Point(12, 21); groupBox1.Name = "groupBox1"; groupBox1.Padding = new Padding(3, 0, 3, 3); - groupBox1.Size = new Size(860, 120); + groupBox1.Size = new Size(838, 120); groupBox1.TabIndex = 3; groupBox1.TabStop = false; // + // toolStrip2 + // + toolStrip2.Anchor = AnchorStyles.Top | AnchorStyles.Right; + toolStrip2.Dock = DockStyle.None; + toolStrip2.GripStyle = ToolStripGripStyle.Hidden; + toolStrip2.Items.AddRange(new ToolStripItem[] { prgOveral, toolStripLabel1, btnSkipCurRange, prgCurRange, toolStripLabel2 }); + toolStrip2.Location = new Point(386, 52); + toolStrip2.Name = "toolStrip2"; + toolStrip2.RightToLeft = RightToLeft.Yes; + toolStrip2.Size = new Size(446, 28); + toolStrip2.TabIndex = 14; + toolStrip2.Text = "toolStrip2"; + // + // prgOveral + // + prgOveral.AutoSize = false; + prgOveral.Name = "prgOveral"; + prgOveral.Size = new Size(145, 25); + prgOveral.ToolTipText = "Overal progress"; + // + // toolStripLabel1 + // + toolStripLabel1.Name = "toolStripLabel1"; + toolStripLabel1.Size = new Size(44, 25); + toolStripLabel1.Text = ":Overal"; + // + // btnSkipCurRange + // + btnSkipCurRange.AccessibleDescription = "A button to allow you skipp current IP range and go for next range"; + btnSkipCurRange.AccessibleName = "Skip current IP range"; + btnSkipCurRange.DisplayStyle = ToolStripItemDisplayStyle.Text; + btnSkipCurRange.DropDownItems.AddRange(new ToolStripItem[] { mnuSkipAfterFoundIPs, mnuSkipAfterAWhile, toolStripSeparator6, mnuSkipAfter10Percent, mnuSkipAfter30Percent, mnuSkipAfter50Percent }); + btnSkipCurRange.Image = (Image)resources.GetObject("btnSkipCurRange.Image"); + btnSkipCurRange.ImageTransparentColor = Color.Magenta; + btnSkipCurRange.Margin = new Padding(2, 1, 2, 2); + btnSkipCurRange.Name = "btnSkipCurRange"; + btnSkipCurRange.Padding = new Padding(6, 0, 0, 0); + btnSkipCurRange.RightToLeft = RightToLeft.No; + btnSkipCurRange.Size = new Size(51, 25); + btnSkipCurRange.Text = "Skip"; + btnSkipCurRange.ToolTipText = "Skip curent IP range (Ctrl+N)"; + btnSkipCurRange.ButtonClick += btnSkipCurRange_ButtonClick; + // + // mnuSkipAfterFoundIPs + // + mnuSkipAfterFoundIPs.CheckOnClick = true; + mnuSkipAfterFoundIPs.Name = "mnuSkipAfterFoundIPs"; + mnuSkipAfterFoundIPs.Size = new Size(287, 22); + mnuSkipAfterFoundIPs.Text = "Auto skip after found 5 working IPs"; + mnuSkipAfterFoundIPs.Click += mnuSkipAfterFoundIPs_Click; + // + // mnuSkipAfterAWhile + // + mnuSkipAfterAWhile.CheckOnClick = true; + mnuSkipAfterAWhile.Name = "mnuSkipAfterAWhile"; + mnuSkipAfterAWhile.Size = new Size(287, 22); + mnuSkipAfterAWhile.Text = "Auto skip after 3 minutes of scanning"; + mnuSkipAfterAWhile.Click += mnuSkipAfterAWhile_Click; + // + // toolStripSeparator6 + // + toolStripSeparator6.Name = "toolStripSeparator6"; + toolStripSeparator6.Size = new Size(284, 6); + // + // mnuSkipAfter10Percent + // + mnuSkipAfter10Percent.CheckOnClick = true; + mnuSkipAfter10Percent.Name = "mnuSkipAfter10Percent"; + mnuSkipAfter10Percent.Size = new Size(287, 22); + mnuSkipAfter10Percent.Tag = "10"; + mnuSkipAfter10Percent.Text = "Auto skip after scanning 10% of IP range"; + mnuSkipAfter10Percent.Click += mnuSkipAfter10Percent_Click; + // + // mnuSkipAfter30Percent + // + mnuSkipAfter30Percent.CheckOnClick = true; + mnuSkipAfter30Percent.Name = "mnuSkipAfter30Percent"; + mnuSkipAfter30Percent.Size = new Size(287, 22); + mnuSkipAfter30Percent.Tag = "30"; + mnuSkipAfter30Percent.Text = "Auto skip after scanning 30% of IP range"; + mnuSkipAfter30Percent.Click += mnuSkipAfter30Percent_Click; + // + // mnuSkipAfter50Percent + // + mnuSkipAfter50Percent.CheckOnClick = true; + mnuSkipAfter50Percent.Name = "mnuSkipAfter50Percent"; + mnuSkipAfter50Percent.Size = new Size(287, 22); + mnuSkipAfter50Percent.Tag = "50"; + mnuSkipAfter50Percent.Text = "Auto skip after scanning 50% of IP range"; + mnuSkipAfter50Percent.Click += mnuSkipAfter50Percent_Click; + // + // prgCurRange + // + prgCurRange.AutoSize = false; + prgCurRange.Name = "prgCurRange"; + prgCurRange.Size = new Size(145, 25); + prgCurRange.ToolTipText = "Current IP range progress"; + // + // toolStripLabel2 + // + toolStripLabel2.Name = "toolStripLabel2"; + toolStripLabel2.Size = new Size(50, 25); + toolStripLabel2.Text = ":Current"; + // // toolStrip1 // toolStrip1.AccessibleDescription = "A toolbar including main scan settings and progress info and also start/stop button."; toolStrip1.AccessibleName = "Main scan settings"; toolStrip1.GripStyle = ToolStripGripStyle.Hidden; toolStrip1.ImageScalingSize = new Size(20, 20); - toolStrip1.Items.AddRange(new ToolStripItem[] { btnStart, toolStripSeparator2, comboConcurrent, lblConcurrent, comboTargetSpeed, lblTargetSpeed, comboConfigs, toolStripLabel3, toolStripSeparator1, prgOveral, toolStripLabel1, btnSkipCurRange, prgCurRange, toolStripLabel2 }); + toolStrip1.Items.AddRange(new ToolStripItem[] { btnStart, toolStripSeparator2, comboConcurrent, lblConcurrent, comboCheckType, comboUpTargetSpeed, comboDLTargetSpeed, lblTargetSpeed, comboConfigs, toolStripLabel3 }); toolStrip1.Location = new Point(3, 16); toolStrip1.Name = "toolStrip1"; toolStrip1.RightToLeft = RightToLeft.Yes; - toolStrip1.Size = new Size(854, 33); + toolStrip1.Size = new Size(832, 33); toolStrip1.TabIndex = 1; toolStrip1.TabStop = true; toolStrip1.Text = "toolStrip1"; @@ -272,7 +382,7 @@ private void InitializeComponent() comboConcurrent.Items.AddRange(new object[] { "1", "2", "4", "8", "16", "32" }); comboConcurrent.Name = "comboConcurrent"; comboConcurrent.RightToLeft = RightToLeft.No; - comboConcurrent.Size = new Size(50, 23); + comboConcurrent.Size = new Size(48, 23); comboConcurrent.Text = "4"; comboConcurrent.ToolTipText = "Number of parallel scan processes"; comboConcurrent.TextChanged += comboConcurrent_TextChanged; @@ -283,19 +393,45 @@ private void InitializeComponent() lblConcurrent.Size = new Size(67, 30); lblConcurrent.Text = "Concurrent"; // - // comboTargetSpeed - // - comboTargetSpeed.AccessibleDescription = "A menu to set your desired download speed while testing IPs"; - comboTargetSpeed.AccessibleName = "Target download speed"; - comboTargetSpeed.AutoSize = false; - comboTargetSpeed.DropDownStyle = ComboBoxStyle.DropDownList; - comboTargetSpeed.FlatStyle = FlatStyle.System; - comboTargetSpeed.Items.AddRange(new object[] { "No Speed Test", "20 KB/s", "50 KB/s", "100 KB/s", "200 KB/s", "500 KB/s" }); - comboTargetSpeed.Name = "comboTargetSpeed"; - comboTargetSpeed.RightToLeft = RightToLeft.No; - comboTargetSpeed.Size = new Size(85, 23); - comboTargetSpeed.ToolTipText = "Target Speed"; - comboTargetSpeed.SelectedIndexChanged += comboTargetSpeed_SelectedIndexChanged; + // comboCheckType + // + comboCheckType.AutoSize = false; + comboCheckType.DropDownStyle = ComboBoxStyle.DropDownList; + comboCheckType.FlatStyle = FlatStyle.System; + comboCheckType.Items.AddRange(new object[] { "Only Download", "Only Upload", "Download & Upload" }); + comboCheckType.Margin = new Padding(7, 0, 1, 0); + comboCheckType.Name = "comboCheckType"; + comboCheckType.RightToLeft = RightToLeft.No; + comboCheckType.Size = new Size(130, 23); + comboCheckType.ToolTipText = "Scan Type"; + // + // comboUpTargetSpeed + // + comboUpTargetSpeed.AccessibleDescription = "A menu to set your desired upload speed while testing IPs"; + comboUpTargetSpeed.AccessibleName = "Target upload speed"; + comboUpTargetSpeed.AutoSize = false; + comboUpTargetSpeed.DropDownStyle = ComboBoxStyle.DropDownList; + comboUpTargetSpeed.FlatStyle = FlatStyle.System; + comboUpTargetSpeed.Items.AddRange(new object[] { "10 KB/s", "20 KB/s", "50 KB/s", "100 KB/s", "200 KB/s", "500 KB/s" }); + comboUpTargetSpeed.Name = "comboUpTargetSpeed"; + comboUpTargetSpeed.RightToLeft = RightToLeft.No; + comboUpTargetSpeed.Size = new Size(60, 23); + comboUpTargetSpeed.ToolTipText = "Target Upload Speed"; + comboUpTargetSpeed.SelectedIndexChanged += comboTargetSpeed_SelectedIndexChanged; + // + // comboDLTargetSpeed + // + comboDLTargetSpeed.AccessibleDescription = "A menu to set your desired download speed while testing IPs"; + comboDLTargetSpeed.AccessibleName = "Target download speed"; + comboDLTargetSpeed.AutoSize = false; + comboDLTargetSpeed.DropDownStyle = ComboBoxStyle.DropDownList; + comboDLTargetSpeed.FlatStyle = FlatStyle.System; + comboDLTargetSpeed.Items.AddRange(new object[] { "No Speed Test", "20 KB/s", "50 KB/s", "100 KB/s", "200 KB/s", "500 KB/s", "1000 KB/s" }); + comboDLTargetSpeed.Name = "comboDLTargetSpeed"; + comboDLTargetSpeed.RightToLeft = RightToLeft.No; + comboDLTargetSpeed.Size = new Size(85, 23); + comboDLTargetSpeed.ToolTipText = "Target Download Speed"; + comboDLTargetSpeed.SelectedIndexChanged += comboTargetSpeed_SelectedIndexChanged; // // lblTargetSpeed // @@ -322,102 +458,6 @@ private void InitializeComponent() toolStripLabel3.Size = new Size(43, 30); toolStripLabel3.Text = "Config"; // - // toolStripSeparator1 - // - toolStripSeparator1.Name = "toolStripSeparator1"; - toolStripSeparator1.Size = new Size(6, 33); - // - // prgOveral - // - prgOveral.AutoSize = false; - prgOveral.Name = "prgOveral"; - prgOveral.Size = new Size(90, 25); - prgOveral.ToolTipText = "Overal progress"; - // - // toolStripLabel1 - // - toolStripLabel1.Name = "toolStripLabel1"; - toolStripLabel1.Size = new Size(41, 30); - toolStripLabel1.Text = "Overal"; - // - // btnSkipCurRange - // - btnSkipCurRange.AccessibleDescription = "A button to allow you skipp current IP range and go for next range"; - btnSkipCurRange.AccessibleName = "Skip current IP range"; - btnSkipCurRange.DisplayStyle = ToolStripItemDisplayStyle.Text; - btnSkipCurRange.DropDownItems.AddRange(new ToolStripItem[] { mnuSkipAfterFoundIPs, mnuSkipAfterAWhile, toolStripSeparator6, mnuSkipAfter10Percent, mnuSkipAfter30Percent, mnuSkipAfter50Percent }); - btnSkipCurRange.Image = (Image)resources.GetObject("btnSkipCurRange.Image"); - btnSkipCurRange.ImageTransparentColor = Color.Magenta; - btnSkipCurRange.Margin = new Padding(2, 1, 0, 2); - btnSkipCurRange.Name = "btnSkipCurRange"; - btnSkipCurRange.Padding = new Padding(2, 0, 0, 0); - btnSkipCurRange.RightToLeft = RightToLeft.No; - btnSkipCurRange.Size = new Size(47, 30); - btnSkipCurRange.Text = "Skip"; - btnSkipCurRange.ToolTipText = "Skip curent IP range (Ctrl+N)"; - btnSkipCurRange.ButtonClick += btnSkipCurRange_ButtonClick; - // - // mnuSkipAfterFoundIPs - // - mnuSkipAfterFoundIPs.CheckOnClick = true; - mnuSkipAfterFoundIPs.Name = "mnuSkipAfterFoundIPs"; - mnuSkipAfterFoundIPs.Size = new Size(287, 22); - mnuSkipAfterFoundIPs.Text = "Auto skip after found 5 working IPs"; - mnuSkipAfterFoundIPs.Click += mnuSkipAfterFoundIPs_Click; - // - // mnuSkipAfterAWhile - // - mnuSkipAfterAWhile.CheckOnClick = true; - mnuSkipAfterAWhile.Name = "mnuSkipAfterAWhile"; - mnuSkipAfterAWhile.Size = new Size(287, 22); - mnuSkipAfterAWhile.Text = "Auto skip after 3 minutes of scanning"; - mnuSkipAfterAWhile.Click += mnuSkipAfterAWhile_Click; - // - // toolStripSeparator6 - // - toolStripSeparator6.Name = "toolStripSeparator6"; - toolStripSeparator6.Size = new Size(284, 6); - // - // mnuSkipAfter10Percent - // - mnuSkipAfter10Percent.CheckOnClick = true; - mnuSkipAfter10Percent.Name = "mnuSkipAfter10Percent"; - mnuSkipAfter10Percent.Size = new Size(287, 22); - mnuSkipAfter10Percent.Tag = "10"; - mnuSkipAfter10Percent.Text = "Auto skip after scanning 10% of IP range"; - mnuSkipAfter10Percent.Click += mnuSkipAfter10Percent_Click; - // - // mnuSkipAfter30Percent - // - mnuSkipAfter30Percent.CheckOnClick = true; - mnuSkipAfter30Percent.Name = "mnuSkipAfter30Percent"; - mnuSkipAfter30Percent.Size = new Size(287, 22); - mnuSkipAfter30Percent.Tag = "30"; - mnuSkipAfter30Percent.Text = "Auto skip after scanning 30% of IP range"; - mnuSkipAfter30Percent.Click += mnuSkipAfter30Percent_Click; - // - // mnuSkipAfter50Percent - // - mnuSkipAfter50Percent.CheckOnClick = true; - mnuSkipAfter50Percent.Name = "mnuSkipAfter50Percent"; - mnuSkipAfter50Percent.Size = new Size(287, 22); - mnuSkipAfter50Percent.Tag = "50"; - mnuSkipAfter50Percent.Text = "Auto skip after scanning 50% of IP range"; - mnuSkipAfter50Percent.Click += mnuSkipAfter50Percent_Click; - // - // prgCurRange - // - prgCurRange.AutoSize = false; - prgCurRange.Name = "prgCurRange"; - prgCurRange.Size = new Size(90, 25); - prgCurRange.ToolTipText = "Current IP range progress"; - // - // toolStripLabel2 - // - toolStripLabel2.Name = "toolStripLabel2"; - toolStripLabel2.Size = new Size(47, 30); - toolStripLabel2.Text = "Current"; - // // lblDebugMode // lblDebugMode.Anchor = AnchorStyles.Top | AnchorStyles.Right; @@ -425,7 +465,7 @@ private void InitializeComponent() lblDebugMode.BackColor = SystemColors.Control; lblDebugMode.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); lblDebugMode.ForeColor = Color.Red; - lblDebugMode.Location = new Point(707, 94); + lblDebugMode.Location = new Point(374, 92); lblDebugMode.Name = "lblDebugMode"; lblDebugMode.Size = new Size(143, 15); lblDebugMode.TabIndex = 13; @@ -438,9 +478,9 @@ private void InitializeComponent() btnCopyFastestIP.AccessibleDescription = "A button for copy fastest found IP address into the clipboard"; btnCopyFastestIP.AccessibleName = "Copy fastest IP address"; btnCopyFastestIP.Anchor = AnchorStyles.Top | AnchorStyles.Right; - btnCopyFastestIP.Location = new Point(703, 55); + btnCopyFastestIP.Location = new Point(729, 87); btnCopyFastestIP.Name = "btnCopyFastestIP"; - btnCopyFastestIP.Size = new Size(151, 25); + btnCopyFastestIP.Size = new Size(103, 25); btnCopyFastestIP.TabIndex = 2; btnCopyFastestIP.Text = "Copy fastest IP"; btnCopyFastestIP.UseVisualStyleBackColor = true; @@ -455,11 +495,11 @@ private void InitializeComponent() txtFastestIP.BackColor = Color.White; txtFastestIP.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); txtFastestIP.ForeColor = Color.Green; - txtFastestIP.Location = new Point(494, 57); + txtFastestIP.Location = new Point(539, 89); txtFastestIP.Name = "txtFastestIP"; txtFastestIP.PlaceholderText = "Fastest IP"; txtFastestIP.ReadOnly = true; - txtFastestIP.Size = new Size(203, 23); + txtFastestIP.Size = new Size(183, 23); txtFastestIP.TabIndex = 3; // // lblTotalWorkingIPs @@ -515,7 +555,7 @@ private void InitializeComponent() btnLoadIPRanges.AccessibleDescription = "A botton to allow you to load your custom Cloudflare IP ranges into the app"; btnLoadIPRanges.AccessibleName = "Load custom IP ranges"; btnLoadIPRanges.Anchor = AnchorStyles.Top | AnchorStyles.Right; - btnLoadIPRanges.Location = new Point(550, 8); + btnLoadIPRanges.Location = new Point(528, 8); btnLoadIPRanges.Name = "btnLoadIPRanges"; btnLoadIPRanges.Size = new Size(104, 23); btnLoadIPRanges.TabIndex = 4; @@ -528,7 +568,7 @@ private void InitializeComponent() // checkScanInRandomOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; checkScanInRandomOrder.AutoSize = true; - checkScanInRandomOrder.Location = new Point(352, 11); + checkScanInRandomOrder.Location = new Point(330, 11); checkScanInRandomOrder.Name = "checkScanInRandomOrder"; checkScanInRandomOrder.Size = new Size(194, 19); checkScanInRandomOrder.TabIndex = 5; @@ -539,12 +579,12 @@ private void InitializeComponent() // listResults // listResults.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - listResults.Columns.AddRange(new ColumnHeader[] { hdrIP, hdrDelay }); + listResults.Columns.AddRange(new ColumnHeader[] { hdrIP, hdrDLDelay, hdrUPDelay }); listResults.FullRowSelect = true; listResults.GridLines = true; listResults.Location = new Point(0, 40); listResults.Name = "listResults"; - listResults.Size = new Size(852, 219); + listResults.Size = new Size(830, 219); listResults.TabIndex = 4; listResults.UseCompatibleStateImageBehavior = false; listResults.View = View.Details; @@ -558,10 +598,15 @@ private void InitializeComponent() hdrIP.Text = "IP Address"; hdrIP.Width = 140; // - // hdrDelay + // hdrDLDelay + // + hdrDLDelay.Text = "Dowload Delay"; + hdrDLDelay.Width = 120; + // + // hdrUPDelay // - hdrDelay.Text = "Delay"; - hdrDelay.Width = 90; + hdrUPDelay.Text = "Upload Delay"; + hdrUPDelay.Width = 120; // // mnuListView // @@ -633,7 +678,7 @@ private void InitializeComponent() // splitContainer1.Panel2 // splitContainer1.Panel2.Controls.Add(txtLog); - splitContainer1.Size = new Size(860, 480); + splitContainer1.Size = new Size(838, 480); splitContainer1.SplitterDistance = 294; splitContainer1.TabIndex = 7; // @@ -647,7 +692,7 @@ private void InitializeComponent() tabControl1.Location = new Point(0, 0); tabControl1.Name = "tabControl1"; tabControl1.SelectedIndex = 0; - tabControl1.Size = new Size(860, 294); + tabControl1.Size = new Size(838, 294); tabControl1.TabIndex = 4; // // tabPageCFRanges @@ -664,7 +709,7 @@ private void InitializeComponent() tabPageCFRanges.Location = new Point(4, 24); tabPageCFRanges.Name = "tabPageCFRanges"; tabPageCFRanges.Padding = new Padding(3); - tabPageCFRanges.Size = new Size(852, 266); + tabPageCFRanges.Size = new Size(830, 266); tabPageCFRanges.TabIndex = 1; tabPageCFRanges.Text = "Cloudflare IP ranges"; // @@ -675,7 +720,7 @@ private void InitializeComponent() listCFIPList.Columns.AddRange(new ColumnHeader[] { headIPRange, headTotalIPs }); listCFIPList.Location = new Point(0, 35); listCFIPList.Name = "listCFIPList"; - listCFIPList.Size = new Size(850, 223); + listCFIPList.Size = new Size(828, 223); listCFIPList.TabIndex = 0; listCFIPList.UseCompatibleStateImageBehavior = false; listCFIPList.View = View.Details; @@ -705,7 +750,7 @@ private void InitializeComponent() // btnSelectNoneIPRanges.AccessibleName = "Unselect all Cloudflare IP ranges"; btnSelectNoneIPRanges.Anchor = AnchorStyles.Top | AnchorStyles.Right; - btnSelectNoneIPRanges.Location = new Point(661, 9); + btnSelectNoneIPRanges.Location = new Point(639, 9); btnSelectNoneIPRanges.Name = "btnSelectNoneIPRanges"; btnSelectNoneIPRanges.Size = new Size(88, 23); btnSelectNoneIPRanges.TabIndex = 2; @@ -717,7 +762,7 @@ private void InitializeComponent() // btnSelectAllIPRanges.AccessibleName = "Select all Cloudflare IP ranges"; btnSelectAllIPRanges.Anchor = AnchorStyles.Top | AnchorStyles.Right; - btnSelectAllIPRanges.Location = new Point(758, 9); + btnSelectAllIPRanges.Location = new Point(736, 9); btnSelectAllIPRanges.Name = "btnSelectAllIPRanges"; btnSelectAllIPRanges.Size = new Size(88, 23); btnSelectAllIPRanges.TabIndex = 1; @@ -739,7 +784,7 @@ private void InitializeComponent() tabPageResults.Location = new Point(4, 24); tabPageResults.Name = "tabPageResults"; tabPageResults.Padding = new Padding(3); - tabPageResults.Size = new Size(852, 266); + tabPageResults.Size = new Size(830, 266); tabPageResults.TabIndex = 0; tabPageResults.Text = "Scan Results"; tabPageResults.UseVisualStyleBackColor = true; @@ -793,7 +838,7 @@ private void InitializeComponent() mnuMain.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem, toolsToolStripMenuItem, helpToolStripMenuItem }); mnuMain.Location = new Point(0, 0); mnuMain.Name = "mnuMain"; - mnuMain.Size = new Size(886, 24); + mnuMain.Size = new Size(864, 24); mnuMain.TabIndex = 8; mnuMain.Text = "menuStrip1"; // @@ -1010,11 +1055,12 @@ private void InitializeComponent() // toolStripBottom // toolStripBottom.Dock = DockStyle.Bottom; + toolStripBottom.GripStyle = ToolStripGripStyle.Hidden; toolStripBottom.ImageScalingSize = new Size(20, 20); toolStripBottom.Items.AddRange(new ToolStripItem[] { btnFrontingErrors, toolStripSeparator3, btnDownloadErrors, toolStripSeparator4, lblAutoSkipStatus, seperatorAutoSkip, lblRunningWorkers, linkBuyMeCoffee, linkGithub, seperatorPaused, lblScanPaused }); toolStripBottom.Location = new Point(0, 628); toolStripBottom.Name = "toolStripBottom"; - toolStripBottom.Size = new Size(886, 33); + toolStripBottom.Size = new Size(864, 33); toolStripBottom.TabIndex = 9; toolStripBottom.Text = "toolStrip2"; // @@ -1052,15 +1098,15 @@ private void InitializeComponent() btnDownloadErrors.Image = (Image)resources.GetObject("btnDownloadErrors.Image"); btnDownloadErrors.ImageTransparentColor = Color.Magenta; btnDownloadErrors.Name = "btnDownloadErrors"; - btnDownloadErrors.Size = new Size(132, 30); - btnDownloadErrors.Text = "Download errors: 0%"; + btnDownloadErrors.Size = new Size(123, 30); + btnDownloadErrors.Text = "DL && UP errors: 0%"; btnDownloadErrors.ButtonClick += btnDownloadErrors_ButtonClick; // // mnuCopyDownloadErrors // mnuCopyDownloadErrors.Name = "mnuCopyDownloadErrors"; - mnuCopyDownloadErrors.Size = new Size(191, 22); - mnuCopyDownloadErrors.Text = "Copy download errors"; + mnuCopyDownloadErrors.Size = new Size(183, 22); + mnuCopyDownloadErrors.Text = "Copy DL && UP errors"; mnuCopyDownloadErrors.Click += mnuCopyDownloadErrors_Click; // // toolStripSeparator4 @@ -1121,11 +1167,17 @@ private void InitializeComponent() lblScanPaused.ToolTipText = "Scan is Paused"; lblScanPaused.Visible = false; // + // toolStripLabel4 + // + toolStripLabel4.Name = "toolStripLabel4"; + toolStripLabel4.Size = new Size(86, 22); + toolStripLabel4.Text = "toolStripLabel4"; + // // frmMain // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(886, 661); + ClientSize = new Size(864, 661); Controls.Add(toolStripBottom); Controls.Add(mnuMain); Controls.Add(splitContainer1); @@ -1134,7 +1186,7 @@ private void InitializeComponent() KeyPreview = true; MaximizeBox = false; MaximumSize = new Size(1200, 896); - MinimumSize = new Size(894, 690); + MinimumSize = new Size(880, 690); Name = "frmMain"; Text = "Cloudflare Scan"; FormClosing += frmMain_FormClosing; @@ -1142,6 +1194,8 @@ private void InitializeComponent() KeyPress += frmMain_KeyPress; groupBox1.ResumeLayout(false); groupBox1.PerformLayout(); + toolStrip2.ResumeLayout(false); + toolStrip2.PerformLayout(); toolStrip1.ResumeLayout(false); toolStrip1.PerformLayout(); mnuListView.ResumeLayout(false); @@ -1173,7 +1227,7 @@ private void InitializeComponent() private GroupBox groupBox1; private ToolTip toolTip1; private ListView listResults; - private ColumnHeader hdrDelay; + private ColumnHeader hdrDLDelay; private ColumnHeader hdrIP; private ComboBox comboResults; private Label lblTotalWorkingIPs; @@ -1219,13 +1273,13 @@ private void InitializeComponent() private ToolStripComboBox comboConcurrent; private ToolStripProgressBar prgOveral; private ToolStripLabel lblConcurrent; - private ToolStripComboBox comboTargetSpeed; + private ToolStripComboBox comboDLTargetSpeed; + private ToolStripComboBox comboUpTargetSpeed; private ToolStripLabel lblTargetSpeed; private ToolStripProgressBar prgCurRange; private ToolStripLabel toolStripLabel1; private ToolStripLabel toolStripLabel2; private ToolStripSeparator toolStripSeparator2; - private ToolStripSeparator toolStripSeparator1; private ToolStripSplitButton btnStart; private ToolStripMenuItem mnuPauseScan; private ToolStripSplitButton btnSkipCurRange; @@ -1273,5 +1327,9 @@ private void InitializeComponent() private ToolStripMenuItem mnuHelpDiagnose; private ToolStripLabel lblScanPaused; private ToolStripSeparator seperatorPaused; + private ToolStrip toolStrip2; + private ToolStripLabel toolStripLabel4; + private ToolStripComboBox comboCheckType; + private ColumnHeader hdrUPDelay; } } \ No newline at end of file diff --git a/windows/frmMain.cs b/windows/frmMain.cs index f5cca7df..c0ddb415 100644 --- a/windows/frmMain.cs +++ b/windows/frmMain.cs @@ -6,9 +6,12 @@ using System.Net; using System.Net.NetworkInformation; using System.Security.Policy; +using System.Text; +using System.Threading; using System.Windows.Forms; using System.Windows.Forms.Automation; using WinCFScan.Classes; +using WinCFScan.Classes.Checker; using WinCFScan.Classes.Config; using WinCFScan.Classes.HTTPRequest; using WinCFScan.Classes.IP; @@ -41,6 +44,9 @@ public partial class frmMain : Form private bool showDiagnosResultMessageBox = false; // only when new config is added private bool isInDiagnosingMode = false; + private ScanType? lastScanType; // in all - in prev, diagnose + private CheckType checkType; // download - upload - both + public frmMain() { InitializeComponent(); @@ -65,13 +71,21 @@ public frmMain() isAppCongigValid = false; } + //var client = new HttpClient(); + //string dlUrl = "https://" + ConfigManager.Instance.getAppConfig().scanDomain; + //HttpContent c = new StringContent(new String('*', 900_000), Encoding.UTF8, "text/plain"); + //client.Timeout = TimeSpan.FromSeconds(10); + //var rr = client.PostAsync(dlUrl, c).Result; + scanEngine = new ScanEngine(); loadLastResultsComboList(); - comboTargetSpeed.SelectedIndex = 3; // 100kb/s - comboDownloadTimeout.SelectedIndex = 0; //2 seconds timeout + comboDLTargetSpeed.SelectedIndex = 3; // 100kb/s + comboUpTargetSpeed.SelectedIndex = 2; // 50kb/s + comboCheckType.SelectedIndex = 0; // Only Download + comboDownloadTimeout.SelectedIndex = 0; // 2 seconds timeout loadCustomConfigsComboList(); appVersion = AppUpdateChecker.getCurrentVersion(); @@ -176,7 +190,7 @@ private void btnStart_ButtonClick(object sender, EventArgs e) startStopScan((ScanType)scanType); } - private ScanType? lastScanType; + private void startStopScan(ScanType scanType = ScanType.SCAN_CLOUDFLARE_IPS) { @@ -206,7 +220,7 @@ private void startStopScan(ScanType scanType = ScanType.SCAN_CLOUDFLARE_IPS) { // diagnose case ScanType.DIAGNOSING: - scanEngine.setPrevResults(new ResultItem(0, diagnoseIPAddress)); + scanEngine.setPrevResults(new ResultItem(0, 0, diagnoseIPAddress)); addTextLog($"Start diagnosing for {diagnoseIPAddress}..."); break; @@ -254,18 +268,20 @@ private void startStopScan(ScanType scanType = ScanType.SCAN_CLOUDFLARE_IPS) // prepare scan engine bool isDiagnosing = scanType == ScanType.DIAGNOSING; - scanEngine.targetSpeed = getTargetSpeed(); // set target speed + scanEngine.dlTargetSpeed = getDownloadTargetSpeed(); // set dl target speed scanEngine.scanConfig = getSelectedV2rayConfig(); // set scan config - scanEngine.downloadTimeout = getDownloadTimeout(); // set download timeout + scanEngine.checkTimeout = getDownloadTimeout(); // set download timeout scanEngine.isDiagnosing = isDiagnosing; // is diagnosing scanEngine.isRandomScan = checkScanInRandomOrder.Checked; // is random scan + scanEngine.checkType = getSelectedCheckType(); // upload - download - both + scanEngine.upTargetSpeed = getUploadTargetSpeed(); // set upload target speed string scanConfigContent = scanEngine.scanConfig.content; - Tools.logStep($"Starting scan engine with target speed: {scanEngine.targetSpeed.getTargetSpeed():n0}, dl timeout: {scanEngine.downloadTimeout}, " + + Tools.logStep($"Starting scan engine with target speed: {scanEngine.dlTargetSpeed.getTargetSpeed():n0}, dl timeout: {scanEngine.checkTimeout}, " + $"config: '{scanEngine.scanConfig}' => " + $"{scanConfigContent.Substring(0, Math.Min(150, scanConfigContent.Length))}...", isDiagnosing); - if(scanEngine.isRandomScan && scanType == ScanType.SCAN_CLOUDFLARE_IPS) + if (scanEngine.isRandomScan && scanType == ScanType.SCAN_CLOUDFLARE_IPS) { addTextLog("Scan in random order is enabled.", true); } @@ -361,7 +377,8 @@ private void updateUIControls(bool isStarting, ScanType scanType = ScanType.SCAN btnScanInPrevResults.Enabled = false; btnResultsActions.Enabled = false; comboConcurrent.Enabled = false; - comboTargetSpeed.Enabled = false; + comboUpTargetSpeed.Enabled = false; + comboDLTargetSpeed.Enabled = false; comboConfigs.Enabled = false; timerProgress.Enabled = true; //btnSkipCurRange.Enabled = true; @@ -383,7 +400,8 @@ private void updateUIControls(bool isStarting, ScanType scanType = ScanType.SCAN { comboConcurrent.Enabled = true; } - comboTargetSpeed.Enabled = true; + comboDLTargetSpeed.Enabled = true; + comboUpTargetSpeed.Enabled = true; comboConfigs.Enabled = true; if (!isScanPaused()) @@ -433,7 +451,8 @@ private void updateConrtolsProgress(bool forceUpdate = false) lblTotalWorkingIPs.Text = $"Total working IPs found: {pInf.scanResults.totalFoundWorkingIPs:n0}"; if (pInf.scanResults.fastestIP != null) { - txtFastestIP.Text = $"{pInf.scanResults.fastestIP.ip} - {pInf.scanResults.fastestIP.delay:n0} ms"; + long delay = scanEngine.checkType == CheckType.UPLOAD ? pInf.scanResults.fastestIP.uploadDelay : pInf.scanResults.fastestIP.downloadDelay; + txtFastestIP.Text = $"{pInf.scanResults.fastestIP.ip} - {delay:n0} ms"; } lblRunningWorkers.Text = $"Threads: {pInf.curentWorkingThreads}"; @@ -453,10 +472,10 @@ private void updateConrtolsProgress(bool forceUpdate = false) // exception rate pInf.frontingExceptions.setControlColorStyles(btnFrontingErrors); - pInf.downloadExceptions.setControlColorStyles(btnDownloadErrors); + pInf.downloadUploadExceptions.setControlColorStyles(btnDownloadErrors); btnFrontingErrors.Text = $"Fronting Errors : {pInf.frontingExceptions.getErrorRate():f1}%"; - btnDownloadErrors.Text = $"Download Errors : {pInf.downloadExceptions.getErrorRate():f1}%"; - btnFrontingErrors.ToolTipText = $"Total errors: {pInf.downloadExceptions.getTotalErros()}"; + btnDownloadErrors.Text = $"Download Errors : {pInf.downloadUploadExceptions.getErrorRate():f1}%"; + btnFrontingErrors.ToolTipText = $"Total errors: {pInf.downloadUploadExceptions.getTotalErros()}"; btnDownloadErrors.ToolTipText = $"Total errors: {pInf.frontingExceptions.getTotalErros()}"; } } @@ -592,7 +611,7 @@ private void addResulItemsToListView(List? workingIPs) foreach (ResultItem resultItem in workingIPs) { index++; - listResults.Items.Add(new ListViewItem(new string[] { resultItem.ip, resultItem.delay.ToString() })); + listResults.Items.Add(new ListViewItem(new string[] { resultItem.ip, resultItem.downloadDelay.ToString(), resultItem.uploadDelay.ToString() })); } listResults.EndUpdate(); listResults.ListViewItemSorter = listResultsColumnSorter; @@ -864,13 +883,26 @@ private void loadCFIPListView() updateCFIPListStatusText(); } + private CheckType getSelectedCheckType() + { + return (CheckType)comboCheckType.SelectedIndex; + } + + private ScanSpeed getDownloadTargetSpeed() + { + int speed; + if (int.TryParse(comboDLTargetSpeed.SelectedItem.ToString().Replace(" KB/s", ""), out speed)) + return new ScanSpeed(speed); + else + return new ScanSpeed(0); + } - private ScanSpeed getTargetSpeed() + private ScanSpeed getUploadTargetSpeed() { int speed; - if (int.TryParse(comboTargetSpeed.SelectedItem.ToString().Replace(" KB/s", ""), out speed)) + if (int.TryParse(comboUpTargetSpeed.SelectedItem.ToString().Replace(" KB/s", ""), out speed)) return new ScanSpeed(speed); else return new ScanSpeed(0); @@ -1036,7 +1068,7 @@ private void scanASingleIPAddressToolStripMenuItem_Click(object sender, EventArg string ipAddr; if (getIPFromUser(out ipAddr, "Test Single IP Address")) { - testAvgSingleIP(ipAddr, 1, getTargetSpeed(), getSelectedV2rayConfig(), getDownloadTimeout()); + testAvgSingleIP(ipAddr, 1, getDownloadTargetSpeed(), getSelectedV2rayConfig(), getDownloadTimeout()); } } @@ -1235,7 +1267,7 @@ private void btnFrontingErrors_ButtonClick(object sender, EventArgs e) private void btnDownloadErrors_ButtonClick(object sender, EventArgs e) { - ExceptionMonitor downloadExceptions = scanEngine.progressInfo.downloadExceptions; + ExceptionMonitor downloadExceptions = scanEngine.progressInfo.downloadUploadExceptions; if (downloadExceptions.hasException()) { addTextLog(downloadExceptions.getTopExceptions()); @@ -1244,7 +1276,7 @@ private void btnDownloadErrors_ButtonClick(object sender, EventArgs e) private void mnuCopyDownloadErrors_Click(object sender, EventArgs e) { - if (setClipboard(scanEngine.progressInfo.downloadExceptions.getTopExceptions(7))) + if (setClipboard(scanEngine.progressInfo.downloadUploadExceptions.getTopExceptions(7))) { addTextLog("Errors copied to the clipboard."); } @@ -1435,7 +1467,8 @@ private void testAvgSingleIP(string IPAddress, int rounds, ScanSpeed targetSpeed for (int i = 1; i <= rounds; i++) { // test - var checker = new CheckIPWorking(IPAddress, targetSpeed, v2rayConfig, downloadTimeout); + // todo: set upload speed + var checker = new CheckIPWorking(IPAddress, targetSpeed, targetSpeed, v2rayConfig, getSelectedCheckType(), downloadTimeout); var success = checker.check(); long DLDuration = checker.downloadDuration; @@ -1480,7 +1513,7 @@ private void testSingleIPAddress(string IPAddress) { addTextLog($"Testing {IPAddress} ..."); - var checker = new CheckIPWorking(IPAddress, getTargetSpeed(), getSelectedV2rayConfig(), getDownloadTimeout()); + var checker = new CheckIPWorking(IPAddress, getDownloadTargetSpeed(), getUploadTargetSpeed(), getSelectedV2rayConfig(), getSelectedCheckType(), getDownloadTimeout()); var success = checker.check(); if (success) @@ -1509,7 +1542,7 @@ private void testSelectedIPAddresses(int rounds = 1) .ToArray(); ; - var speed = getTargetSpeed(); + var speed = getDownloadTargetSpeed(); var conf = getSelectedV2rayConfig(); var timeout = getDownloadTimeout(); @@ -1574,7 +1607,7 @@ private void testThisIPAddressToolStripMenuItem_Click(object sender, EventArgs e if (ip != null) { - testAvgSingleIP(ip, 1, getTargetSpeed(), getSelectedV2rayConfig(), getDownloadTimeout()); + testAvgSingleIP(ip, 1, getDownloadTargetSpeed(), getSelectedV2rayConfig(), getDownloadTimeout()); } } @@ -1645,7 +1678,7 @@ private void listResults_SelectedIndexChanged(object sender, EventArgs e) private void comboTargetSpeed_SelectedIndexChanged(object sender, EventArgs e) { - if (comboTargetSpeed.SelectedIndex == 0) + if (comboDLTargetSpeed.SelectedIndex == 0) { addTextLog("By selecting this option we won't test download speed via VPN and just quickly return all resolvable IPs."); } @@ -1706,8 +1739,8 @@ private void mnuAddIPToList_Click(object sender, EventArgs e) string ipAddr; if (getIPFromUser(out ipAddr, "Add IP To List")) { - listResults.Items.Add(new ListViewItem(new string[] { ipAddr, "0" })); - currentScanResults.Add(new ResultItem(0, ipAddr)); + listResults.Items.Add(new ListViewItem(new string[] { ipAddr, "0", "0" })); + currentScanResults.Add(new ResultItem(0, 0, ipAddr)); } } diff --git a/windows/frmMain.resx b/windows/frmMain.resx index ada3f680..e25bd047 100644 --- a/windows/frmMain.resx +++ b/windows/frmMain.resx @@ -63,11 +63,11 @@ 122, 17 - - 1002, 21 + + 1246, 21 - + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACRSURBVDhPY/j27dt/SjDYACcnJ7IwigEf3n8kCZNswPNb @@ -76,7 +76,10 @@ AAAAAElFTkSuQmCC - + + 1002, 21 + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACRSURBVDhPY/j27dt/SjDYACcnJ7IwigEf3n8kCZNswPNb From 0ac1edd32d14bda9b0ea54aeed9cd5ec586b6304 Mon Sep 17 00:00:00 2001 From: goingfine Date: Tue, 25 Apr 2023 13:14:23 +0330 Subject: [PATCH 2/5] prevent false positive on fronting checks --- windows/Classes/Checker/CheckIPWorking.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/Classes/Checker/CheckIPWorking.cs b/windows/Classes/Checker/CheckIPWorking.cs index 1cac8f62..37ef1347 100644 --- a/windows/Classes/Checker/CheckIPWorking.cs +++ b/windows/Classes/Checker/CheckIPWorking.cs @@ -138,7 +138,7 @@ public bool checkFronting(bool withCustumDNSResolver = true, int timeout = 1) var html = client.GetStringAsync(frUrl).Result; Tools.logStep($"Fronting check done in {sw.ElapsedMilliseconds:n0} ms, content: '{html.Substring(0, 50)}'", isDiagnosing); frontingDuration = sw.ElapsedMilliseconds; - return true; + return html.StartsWith("0000000000"); } catch (Exception ex) { From de5d0aeaf7734b9d93bfb355487b1615b77f11a9 Mon Sep 17 00:00:00 2001 From: goingfine Date: Tue, 25 Apr 2023 13:25:20 +0330 Subject: [PATCH 3/5] udate diagnose to include upload results --- windows/Classes/Checker/CheckIPWorking.cs | 7 ++++--- windows/Classes/Checker/CheckResultStatus.cs | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/windows/Classes/Checker/CheckIPWorking.cs b/windows/Classes/Checker/CheckIPWorking.cs index 37ef1347..fae6f8b2 100644 --- a/windows/Classes/Checker/CheckIPWorking.cs +++ b/windows/Classes/Checker/CheckIPWorking.cs @@ -78,7 +78,8 @@ public bool check() Tools.logStep( string.Format(Environment.NewLine + "Fronting Result: {0}", frontingSuccess ? "SUCCESS" : "FAILED") + Environment.NewLine + string.Format("v2ray.exe Execution: {0}", isV2rayExecutionSuccess ? "SUCCESS" : "FAILED") + Environment.NewLine + - string.Format("Download Result: {0}", v2rayDLSuccess ? "SUCCESS" : "FAILED"), isDiagnosing + string.Format("Download Result: {0}", checkResultStatus.isDownSuccess() ? "SUCCESS" : "FAILED") + Environment.NewLine + + string.Format("Upload Result: {0}", checkResultStatus.isUpSuccess() ? "SUCCESS" : "FAILED"), isDiagnosing ); Tools.logStep("\n------------ End IP Check ------------\n", isDiagnosing); @@ -167,7 +168,7 @@ public bool checkFronting(bool withCustumDNSResolver = true, int timeout = 1) private bool checkV2raySpeed() { // check download - if (checkType is CheckType.DOWNLOAD or CheckType.BOTH) + if (checkType is CheckType.DOWNLOAD or CheckType.BOTH || isDiagnosing) { string dlUrl = "https://" + ConfigManager.Instance.getAppConfig().downloadDomain + dlTargetSpeed.getTargetFileSize(checkTimeout); var cs = new CheckSettings(ip, port, checkTimeout, dlUrl, isDiagnosing, checkType, dlTargetSpeed); @@ -185,7 +186,7 @@ private bool checkV2raySpeed() } // check upload - if (checkType is CheckType.UPLOAD or CheckType.BOTH){ + if (checkType is CheckType.UPLOAD or CheckType.BOTH || isDiagnosing){ string upUrl = "https://" + ConfigManager.Instance.getAppConfig().uploadDomain; var cs = new CheckSettings(ip, port, checkTimeout, upUrl, isDiagnosing, checkType, upTargetSpeed); var upChecker = new UploadChecker(cs); diff --git a/windows/Classes/Checker/CheckResultStatus.cs b/windows/Classes/Checker/CheckResultStatus.cs index bb2d3932..f86d1cf2 100644 --- a/windows/Classes/Checker/CheckResultStatus.cs +++ b/windows/Classes/Checker/CheckResultStatus.cs @@ -32,6 +32,16 @@ public bool isSuccess() } } + public bool isDownSuccess() + { + return isDownloadSuccess; + } + + public bool isUpSuccess() + { + return isUploadSuccess; + } + public void setDownloadSuccess() { this.isDownloadSuccess = true; From b4da940ee503735dda0c0e6034feca2273942791 Mon Sep 17 00:00:00 2001 From: goingfine Date: Tue, 25 Apr 2023 14:05:28 +0330 Subject: [PATCH 4/5] udate manual ip tests to include upload results --- windows/frmMain.cs | 60 +++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/windows/frmMain.cs b/windows/frmMain.cs index c0ddb415..f90998ce 100644 --- a/windows/frmMain.cs +++ b/windows/frmMain.cs @@ -921,11 +921,7 @@ private ScanSpeed getUploadTargetSpeed() private void listResults_MouseDoubleClick(object sender, MouseEventArgs e) { - var IPAddress = getSelectedIPAddress(); - if (IPAddress != null) - { - testSingleIPAddress(IPAddress); - } + testSelectedIP(); } private void updateCFIPListStatusText() @@ -1068,7 +1064,7 @@ private void scanASingleIPAddressToolStripMenuItem_Click(object sender, EventArg string ipAddr; if (getIPFromUser(out ipAddr, "Test Single IP Address")) { - testAvgSingleIP(ipAddr, 1, getDownloadTargetSpeed(), getSelectedV2rayConfig(), getDownloadTimeout()); + testAvgSingleIP(ipAddr, 1, getDownloadTargetSpeed(), getUploadTargetSpeed(), getSelectedV2rayConfig(), getDownloadTimeout(), getSelectedCheckType()); } } @@ -1455,31 +1451,33 @@ private void updateClientConfigCloudflareSubnetsToolStripMenuItem_Click(object s } - private void testAvgSingleIP(string IPAddress, int rounds, ScanSpeed targetSpeed, CustomConfigInfo v2rayConfig, int downloadTimeout) + private void testAvgSingleIP(string IPAddress, int rounds, ScanSpeed dlSpeed, ScanSpeed upSpeed, CustomConfigInfo v2rayConfig, int downloadTimeout, CheckType checkType = CheckType.DOWNLOAD) { - addTextLog($"Testing {IPAddress} for {rounds} rounds..."); + addTextLog($"Testing {IPAddress} for {rounds} rounds, Scan Type: {checkType}..."); int totalSuccessCount = 0, totalFailedCount = 0; - long bestDLDuration = 99999, bestFrontingDuration = 99999, totalDLDuration = 0, totalFrontingDuration = 0; - long averageDLDuration = 0, averageFrontingDuration = 0; + long bestDLDuration = 99999, bestUPDuration = 9999, bestFrontingDuration = 99999, totalDLDuration = 0, totalUPDuration = 0, totalFrontingDuration = 0; + long averageDLDuration = 0, averageUPDuration = 0, averageFrontingDuration = 0; for (int i = 1; i <= rounds; i++) { // test - // todo: set upload speed - var checker = new CheckIPWorking(IPAddress, targetSpeed, targetSpeed, v2rayConfig, getSelectedCheckType(), downloadTimeout); + var checker = new CheckIPWorking(IPAddress, dlSpeed, upSpeed, v2rayConfig, checkType, downloadTimeout); var success = checker.check(); long DLDuration = checker.downloadDuration; + long UPDuration = checker.uploadDuration; long FrontingDuration = checker.frontingDuration; if (success) { totalSuccessCount++; bestDLDuration = Math.Min(DLDuration, bestDLDuration); + bestUPDuration = Math.Min(UPDuration, bestUPDuration); bestFrontingDuration = Math.Min(FrontingDuration, bestFrontingDuration); totalDLDuration += DLDuration; + totalUPDuration += UPDuration; totalFrontingDuration += FrontingDuration; } else @@ -1494,10 +1492,12 @@ private void testAvgSingleIP(string IPAddress, int rounds, ScanSpeed targetSpeed if (totalSuccessCount > 0) { averageDLDuration = totalDLDuration / totalSuccessCount; + averageUPDuration = totalUPDuration / totalSuccessCount; averageFrontingDuration = totalFrontingDuration / totalSuccessCount; string results = $"{IPAddress} => {totalSuccessCount}/{rounds} was successful." + Environment.NewLine + - $"\tDownload: Best {bestDLDuration:n0} ms, Average: {averageDLDuration:n0} ms" + Environment.NewLine + + (bestDLDuration > 0 ? $"\tDownload: Best {bestDLDuration:n0} ms, Average: {averageDLDuration:n0} ms" + Environment.NewLine : "") + + (bestUPDuration> 0 ? $"\tUpload : Best {bestUPDuration:n0} ms, Average: {averageUPDuration:n0} ms" + Environment.NewLine : "") + $"\tFronting: Best {bestFrontingDuration:n0} ms, Average: {averageFrontingDuration:n0} ms" + Environment.NewLine; addTextLog(results); @@ -1509,23 +1509,6 @@ private void testAvgSingleIP(string IPAddress, int rounds, ScanSpeed targetSpeed } - private void testSingleIPAddress(string IPAddress) - { - addTextLog($"Testing {IPAddress} ..."); - - var checker = new CheckIPWorking(IPAddress, getDownloadTargetSpeed(), getUploadTargetSpeed(), getSelectedV2rayConfig(), getSelectedCheckType(), getDownloadTimeout()); - var success = checker.check(); - - if (success) - { - addTextLog($"{IPAddress} is working. Delay: {checker.downloadDuration:n0} ms."); - } - else - { - addTextLog($"{IPAddress} is NOT working."); - } - } - private void testSelectedIPAddresses(int rounds = 1) { if (scanEngine.progressInfo.isScanRunning || isManualTesting) @@ -1542,14 +1525,16 @@ private void testSelectedIPAddresses(int rounds = 1) .ToArray(); ; - var speed = getDownloadTargetSpeed(); + var dlSpeed = getDownloadTargetSpeed(); + var upSpeed = getUploadTargetSpeed(); + var checkType = getSelectedCheckType(); var conf = getSelectedV2rayConfig(); var timeout = getDownloadTimeout(); addTextLog($"Start testing {selectedIPs.Length} IPs for {rounds} rounds..." + Environment.NewLine + - $"\tTest spec: download size: {speed.getTargetFileSizeInt(timeout) / 1000} KB in {timeout} seconds." + Environment.NewLine); + $"\tTest spec: download size: {dlSpeed.getTargetFileSizeInt(timeout) / 1000} KB in {timeout} seconds." + Environment.NewLine); - if (speed.isSpeedZero()) + if (dlSpeed.isSpeedZero()) { addTextLog("** Warning: Testing in NO VPN mode. Choose a target download speed from above settings so we can test base on that target speed."); } @@ -1562,7 +1547,7 @@ private void testSelectedIPAddresses(int rounds = 1) for (int i = 0; i < selectedIPs.Length; i++) { var ip = selectedIPs[i]; - testAvgSingleIP(ip, rounds, speed, conf, timeout); + testAvgSingleIP(ip, rounds, dlSpeed, upSpeed, conf, timeout, checkType); // stop requested if (stopAvgTetingIsRequested) @@ -1602,12 +1587,17 @@ private void btnResultsActions_Click(object sender, EventArgs e) } private void testThisIPAddressToolStripMenuItem_Click(object sender, EventArgs e) + { + testSelectedIP(); + } + + private void testSelectedIP() { var ip = getSelectedIPAddress(); if (ip != null) { - testAvgSingleIP(ip, 1, getDownloadTargetSpeed(), getSelectedV2rayConfig(), getDownloadTimeout()); + testAvgSingleIP(ip, 1, getDownloadTargetSpeed(), getUploadTargetSpeed(), getSelectedV2rayConfig(), getDownloadTimeout(), getSelectedCheckType()); } } From 0e0464f7e83240711259cb4acf9d1e1d9d0e7f64 Mon Sep 17 00:00:00 2001 From: goingfine Date: Tue, 25 Apr 2023 17:36:35 +0330 Subject: [PATCH 5/5] no auto skip in prev result scan mode --- windows/Classes/ScanEngine.cs | 6 ++++++ windows/frmMain.Designer.cs | 15 ++++++++------- windows/frmMain.cs | 11 +++++++---- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/windows/Classes/ScanEngine.cs b/windows/Classes/ScanEngine.cs index b08d929a..29da03d8 100644 --- a/windows/Classes/ScanEngine.cs +++ b/windows/Classes/ScanEngine.cs @@ -41,6 +41,7 @@ internal class ScanEngine private int skipMinPercent; public bool isDiagnosing = false; public bool isRandomScan = false; + private ScanType scanType; public ScanEngine() { @@ -51,6 +52,7 @@ public ScanEngine() public bool resume(ScanType scanType = ScanType.SCAN_CLOUDFLARE_IPS) { + this.scanType = scanType; if (progressInfo.scanStatus != ScanStatus.PAUSED) return false; @@ -61,6 +63,7 @@ public bool resume(ScanType scanType = ScanType.SCAN_CLOUDFLARE_IPS) public bool start(ScanType scanType = ScanType.SCAN_CLOUDFLARE_IPS, int lastIndex = 0) { + this.scanType = scanType; progressInfo.stopRequested = false; progressInfo.pauseRequested = false; @@ -330,6 +333,9 @@ private void monitorExceptions(CheckIPWorking checker) private void checkForAutoSkips() { + // no skip in prev result scan mode + if (scanType == ScanType.SCAN_IN_PERV_RESULTS) + return; // skip after 3 minute if (skipAfterAWhileEnabled) diff --git a/windows/frmMain.Designer.cs b/windows/frmMain.Designer.cs index d77e259a..5e7f4bb2 100644 --- a/windows/frmMain.Designer.cs +++ b/windows/frmMain.Designer.cs @@ -402,7 +402,7 @@ private void InitializeComponent() comboCheckType.Margin = new Padding(7, 0, 1, 0); comboCheckType.Name = "comboCheckType"; comboCheckType.RightToLeft = RightToLeft.No; - comboCheckType.Size = new Size(130, 23); + comboCheckType.Size = new Size(138, 23); comboCheckType.ToolTipText = "Scan Type"; // // comboUpTargetSpeed @@ -465,7 +465,7 @@ private void InitializeComponent() lblDebugMode.BackColor = SystemColors.Control; lblDebugMode.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); lblDebugMode.ForeColor = Color.Red; - lblDebugMode.Location = new Point(374, 92); + lblDebugMode.Location = new Point(289, 92); lblDebugMode.Name = "lblDebugMode"; lblDebugMode.Size = new Size(143, 15); lblDebugMode.TabIndex = 13; @@ -478,9 +478,9 @@ private void InitializeComponent() btnCopyFastestIP.AccessibleDescription = "A button for copy fastest found IP address into the clipboard"; btnCopyFastestIP.AccessibleName = "Copy fastest IP address"; btnCopyFastestIP.Anchor = AnchorStyles.Top | AnchorStyles.Right; - btnCopyFastestIP.Location = new Point(729, 87); + btnCopyFastestIP.Location = new Point(683, 87); btnCopyFastestIP.Name = "btnCopyFastestIP"; - btnCopyFastestIP.Size = new Size(103, 25); + btnCopyFastestIP.Size = new Size(149, 25); btnCopyFastestIP.TabIndex = 2; btnCopyFastestIP.Text = "Copy fastest IP"; btnCopyFastestIP.UseVisualStyleBackColor = true; @@ -495,11 +495,11 @@ private void InitializeComponent() txtFastestIP.BackColor = Color.White; txtFastestIP.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); txtFastestIP.ForeColor = Color.Green; - txtFastestIP.Location = new Point(539, 89); + txtFastestIP.Location = new Point(438, 89); txtFastestIP.Name = "txtFastestIP"; txtFastestIP.PlaceholderText = "Fastest IP"; txtFastestIP.ReadOnly = true; - txtFastestIP.Size = new Size(183, 23); + txtFastestIP.Size = new Size(239, 23); txtFastestIP.TabIndex = 3; // // lblTotalWorkingIPs @@ -533,7 +533,7 @@ private void InitializeComponent() comboResults.FormattingEnabled = true; comboResults.Location = new Point(140, 10); comboResults.Name = "comboResults"; - comboResults.Size = new Size(220, 23); + comboResults.Size = new Size(225, 23); comboResults.TabIndex = 5; toolTip1.SetToolTip(comboResults, "List of last scan results"); comboResults.SelectedIndexChanged += comboResults_SelectedIndexChanged; @@ -1072,6 +1072,7 @@ private void InitializeComponent() btnFrontingErrors.ForeColor = SystemColors.ControlText; btnFrontingErrors.Image = (Image)resources.GetObject("btnFrontingErrors.Image"); btnFrontingErrors.ImageTransparentColor = Color.Magenta; + btnFrontingErrors.Margin = new Padding(10, 1, 0, 2); btnFrontingErrors.Name = "btnFrontingErrors"; btnFrontingErrors.Size = new Size(123, 30); btnFrontingErrors.Text = "Fronting errors: 0%"; diff --git a/windows/frmMain.cs b/windows/frmMain.cs index f90998ce..d345fa95 100644 --- a/windows/frmMain.cs +++ b/windows/frmMain.cs @@ -380,6 +380,7 @@ private void updateUIControls(bool isStarting, ScanType scanType = ScanType.SCAN comboUpTargetSpeed.Enabled = false; comboDLTargetSpeed.Enabled = false; comboConfigs.Enabled = false; + comboCheckType.Enabled = false; timerProgress.Enabled = true; //btnSkipCurRange.Enabled = true; comboResults.Enabled = false; @@ -403,6 +404,7 @@ private void updateUIControls(bool isStarting, ScanType scanType = ScanType.SCAN comboDLTargetSpeed.Enabled = true; comboUpTargetSpeed.Enabled = true; comboConfigs.Enabled = true; + comboCheckType.Enabled = true; if (!isScanPaused()) { @@ -474,7 +476,7 @@ private void updateConrtolsProgress(bool forceUpdate = false) pInf.frontingExceptions.setControlColorStyles(btnFrontingErrors); pInf.downloadUploadExceptions.setControlColorStyles(btnDownloadErrors); btnFrontingErrors.Text = $"Fronting Errors : {pInf.frontingExceptions.getErrorRate():f1}%"; - btnDownloadErrors.Text = $"Download Errors : {pInf.downloadUploadExceptions.getErrorRate():f1}%"; + btnDownloadErrors.Text = $"DL && UP Errors : {pInf.downloadUploadExceptions.getErrorRate():f1}%"; btnFrontingErrors.ToolTipText = $"Total errors: {pInf.downloadUploadExceptions.getTotalErros()}"; btnDownloadErrors.ToolTipText = $"Total errors: {pInf.frontingExceptions.getTotalErros()}"; } @@ -1454,7 +1456,7 @@ private void updateClientConfigCloudflareSubnetsToolStripMenuItem_Click(object s private void testAvgSingleIP(string IPAddress, int rounds, ScanSpeed dlSpeed, ScanSpeed upSpeed, CustomConfigInfo v2rayConfig, int downloadTimeout, CheckType checkType = CheckType.DOWNLOAD) { - addTextLog($"Testing {IPAddress} for {rounds} rounds, Scan Type: {checkType}..."); + addTextLog($"{Environment.NewLine}Testing {IPAddress} for {rounds} round(s), Scan type: {checkType}..."); int totalSuccessCount = 0, totalFailedCount = 0; long bestDLDuration = 99999, bestUPDuration = 9999, bestFrontingDuration = 99999, totalDLDuration = 0, totalUPDuration = 0, totalFrontingDuration = 0; @@ -1495,9 +1497,10 @@ private void testAvgSingleIP(string IPAddress, int rounds, ScanSpeed dlSpeed, Sc averageUPDuration = totalUPDuration / totalSuccessCount; averageFrontingDuration = totalFrontingDuration / totalSuccessCount; - string results = $"{IPAddress} => {totalSuccessCount}/{rounds} was successful." + Environment.NewLine + + // print results + string results = $"{IPAddress} => {totalSuccessCount}/{rounds} test(s) was successful." + Environment.NewLine + (bestDLDuration > 0 ? $"\tDownload: Best {bestDLDuration:n0} ms, Average: {averageDLDuration:n0} ms" + Environment.NewLine : "") + - (bestUPDuration> 0 ? $"\tUpload : Best {bestUPDuration:n0} ms, Average: {averageUPDuration:n0} ms" + Environment.NewLine : "") + + (bestUPDuration > 0 ? $"\tUpload : Best {bestUPDuration:n0} ms, Average: {averageUPDuration:n0} ms" + Environment.NewLine : "") + $"\tFronting: Best {bestFrontingDuration:n0} ms, Average: {averageFrontingDuration:n0} ms" + Environment.NewLine; addTextLog(results);