diff --git a/windows/Classes/CheckIPWorking.cs b/windows/Classes/CheckIPWorking.cs index 362af542..d7860b92 100644 --- a/windows/Classes/CheckIPWorking.cs +++ b/windows/Classes/CheckIPWorking.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Linq; using System.Net; +using System.Net.NetworkInformation; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; @@ -27,6 +28,8 @@ internal class CheckIPWorking private bool isDiagnosing = false; public bool isV2rayExecutionSuccess = false; + + public CheckIPWorking(string ip, ScanSpeed targetSpeed, CustomConfigInfo scanConfig, int downloadTimeout, bool isDiagnosing = false) { this.ip = ip; @@ -236,7 +239,7 @@ private bool createV2rayConfigFile() .Replace("PORTPORT", port) .Replace("HOSTHOST", clientConfig.host) .Replace("CFPORTCFPORT", clientConfig.port) - .Replace("RANDOMHOST", clientConfig.serverName) + .Replace("RANDOMHOST", getRandomSNI(clientConfig.host)) .Replace("IP.IP.IP.IP", this.ip) .Replace("ENDPOINTENDPOINT", clientConfig.path); } @@ -260,6 +263,13 @@ private bool createV2rayConfigFile() } + private string getRandomSNI(string host) + { + var urlParts = host.Split("."); + urlParts[0] = Guid.NewGuid().ToString(); + return string.Join(".", urlParts); + } + // sum of ip segments plus 3000 private string getPortByIP() { @@ -284,6 +294,7 @@ private bool runV2rayProcess() //} startInfo.UseShellExecute = false; startInfo.Arguments = $"run -config=\"{v2rayConfigPath}\""; + //startInfo.Arguments = $"-c \"{v2rayConfigPath}\""; Tools.logStep(Environment.NewLine + "----- Running v2ray.exe -----", isDiagnosing); Tools.logStep($"Starting v2ray.exe with arg: {startInfo.Arguments}", isDiagnosing); bool wasSuccess = false; diff --git a/windows/Classes/IP/IPAddressExtensions.cs b/windows/Classes/IP/IPAddressExtensions.cs index 14758bf0..2d44d908 100644 --- a/windows/Classes/IP/IPAddressExtensions.cs +++ b/windows/Classes/IP/IPAddressExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Net; +using System.Net.NetworkInformation; using System.Text; using System.Threading.Tasks; @@ -56,8 +57,46 @@ public static List getAllIPInRange(string ipAndNet) return getIPRange(splitted[0], Int32.Parse(splitted[1])); } + /// + /// checks for used ports and retrieves the first free port + /// + /// the free port or 0 if it did not find a free port + public static int getAvailablePort(int startingPort) + { + IPEndPoint[] endPoints; + List portArray = new List(); + + IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); + + //getting active connections + TcpConnectionInformation[] connections = properties.GetActiveTcpConnections(); + portArray.AddRange(from n in connections + where n.LocalEndPoint.Port >= startingPort + select n.LocalEndPoint.Port); + + //getting active tcp listners - WCF service listening in tcp + endPoints = properties.GetActiveTcpListeners(); + portArray.AddRange(from n in endPoints + where n.Port >= startingPort + select n.Port); + + //getting active udp listeners + endPoints = properties.GetActiveUdpListeners(); + portArray.AddRange(from n in endPoints + where n.Port >= startingPort + select n.Port); + + portArray.Sort(); + + for (int i = startingPort; i < UInt16.MaxValue; i++) + if (!portArray.Contains(i)) + return i; + + return 0; + } + - public static IPAddress GetBroadcastAddress(this IPAddress address, IPAddress subnetMask) + public static IPAddress GetBroadcastAddress(this IPAddress address, IPAddress subnetMask) { byte[] ipAdressBytes = address.GetAddressBytes(); byte[] subnetMaskBytes = subnetMask.GetAddressBytes(); diff --git a/windows/Properties/latest-version b/windows/Properties/latest-version index 1f937720..6cb8a745 100644 --- a/windows/Properties/latest-version +++ b/windows/Properties/latest-version @@ -1 +1 @@ -v:1.1.8489.35707 \ No newline at end of file +v:1.1.8506.21097 \ No newline at end of file diff --git a/windows/assets/app-config.json b/windows/assets/app-config.json index 77712506..eab93311 100644 --- a/windows/assets/app-config.json +++ b/windows/assets/app-config.json @@ -1,5 +1,5 @@ { "frontDomain": "speed.cloudflare.com/__down?bytes=1000", "scanDomain": "speed.cloudflare.com/__down?bytes=", - "clientConfigUrl": "https://raw.githubusercontent.com/MortezaBashsiz/CFScanner/main/bash/ClientConfig.json" + "clientConfigUrl": "https://raw.githubusercontent.com/MortezaBashsiz/CFScanner/main/config/ClientConfig.json" } \ No newline at end of file diff --git a/windows/frmMain.cs b/windows/frmMain.cs index 5c072515..f5cca7df 100644 --- a/windows/frmMain.cs +++ b/windows/frmMain.cs @@ -65,6 +65,8 @@ public frmMain() isAppCongigValid = false; } + + scanEngine = new ScanEngine(); loadLastResultsComboList(); @@ -287,6 +289,11 @@ private void startStopScan(ScanType scanType = ScanType.SCAN_CLOUDFLARE_IPS) { scanFinished = true; + if (!scanEngine.progressInfo.pauseRequested) + { + lastScanType = null; + } + // don't update results in diagnose test if (!isDiagnosing) currentScanResults = scanEngine.progressInfo.scanResults.workingIPs;