Skip to content

Commit

Permalink
Merge pull request #463 from MortezaBashsiz/win-develop
Browse files Browse the repository at this point in the history
random sni and bug fix
  • Loading branch information
MortezaBashsiz authored Apr 16, 2023
2 parents e80125c + 04d89bb commit 4acb2f2
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
13 changes: 12 additions & 1 deletion windows/Classes/CheckIPWorking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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()
{
Expand All @@ -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;
Expand Down
41 changes: 40 additions & 1 deletion windows/Classes/IP/IPAddressExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -56,8 +57,46 @@ public static List<string> getAllIPInRange(string ipAndNet)
return getIPRange(splitted[0], Int32.Parse(splitted[1]));
}

/// <summary>
/// checks for used ports and retrieves the first free port
/// </summary>
/// <returns>the free port or 0 if it did not find a free port</returns>
public static int getAvailablePort(int startingPort)
{
IPEndPoint[] endPoints;
List<int> portArray = new List<int>();

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();
Expand Down
2 changes: 1 addition & 1 deletion windows/Properties/latest-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v:1.1.8489.35707
v:1.1.8506.21097
2 changes: 1 addition & 1 deletion windows/assets/app-config.json
Original file line number Diff line number Diff line change
@@ -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"
}
7 changes: 7 additions & 0 deletions windows/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public frmMain()
isAppCongigValid = false;
}



scanEngine = new ScanEngine();

loadLastResultsComboList();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4acb2f2

Please sign in to comment.