Skip to content

Commit 4acb2f2

Browse files
Merge pull request #463 from MortezaBashsiz/win-develop
random sni and bug fix
2 parents e80125c + 04d89bb commit 4acb2f2

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

windows/Classes/CheckIPWorking.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.Linq;
55
using System.Net;
6+
using System.Net.NetworkInformation;
67
using System.Text;
78
using System.Threading.Tasks;
89
using System.Windows.Forms;
@@ -27,6 +28,8 @@ internal class CheckIPWorking
2728
private bool isDiagnosing = false;
2829
public bool isV2rayExecutionSuccess = false;
2930

31+
32+
3033
public CheckIPWorking(string ip, ScanSpeed targetSpeed, CustomConfigInfo scanConfig, int downloadTimeout, bool isDiagnosing = false)
3134
{
3235
this.ip = ip;
@@ -236,7 +239,7 @@ private bool createV2rayConfigFile()
236239
.Replace("PORTPORT", port)
237240
.Replace("HOSTHOST", clientConfig.host)
238241
.Replace("CFPORTCFPORT", clientConfig.port)
239-
.Replace("RANDOMHOST", clientConfig.serverName)
242+
.Replace("RANDOMHOST", getRandomSNI(clientConfig.host))
240243
.Replace("IP.IP.IP.IP", this.ip)
241244
.Replace("ENDPOINTENDPOINT", clientConfig.path);
242245
}
@@ -260,6 +263,13 @@ private bool createV2rayConfigFile()
260263

261264
}
262265

266+
private string getRandomSNI(string host)
267+
{
268+
var urlParts = host.Split(".");
269+
urlParts[0] = Guid.NewGuid().ToString();
270+
return string.Join(".", urlParts);
271+
}
272+
263273
// sum of ip segments plus 3000
264274
private string getPortByIP()
265275
{
@@ -284,6 +294,7 @@ private bool runV2rayProcess()
284294
//}
285295
startInfo.UseShellExecute = false;
286296
startInfo.Arguments = $"run -config=\"{v2rayConfigPath}\"";
297+
//startInfo.Arguments = $"-c \"{v2rayConfigPath}\"";
287298
Tools.logStep(Environment.NewLine + "----- Running v2ray.exe -----", isDiagnosing);
288299
Tools.logStep($"Starting v2ray.exe with arg: {startInfo.Arguments}", isDiagnosing);
289300
bool wasSuccess = false;

windows/Classes/IP/IPAddressExtensions.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Net;
5+
using System.Net.NetworkInformation;
56
using System.Text;
67
using System.Threading.Tasks;
78

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

60+
/// <summary>
61+
/// checks for used ports and retrieves the first free port
62+
/// </summary>
63+
/// <returns>the free port or 0 if it did not find a free port</returns>
64+
public static int getAvailablePort(int startingPort)
65+
{
66+
IPEndPoint[] endPoints;
67+
List<int> portArray = new List<int>();
68+
69+
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
70+
71+
//getting active connections
72+
TcpConnectionInformation[] connections = properties.GetActiveTcpConnections();
73+
portArray.AddRange(from n in connections
74+
where n.LocalEndPoint.Port >= startingPort
75+
select n.LocalEndPoint.Port);
76+
77+
//getting active tcp listners - WCF service listening in tcp
78+
endPoints = properties.GetActiveTcpListeners();
79+
portArray.AddRange(from n in endPoints
80+
where n.Port >= startingPort
81+
select n.Port);
82+
83+
//getting active udp listeners
84+
endPoints = properties.GetActiveUdpListeners();
85+
portArray.AddRange(from n in endPoints
86+
where n.Port >= startingPort
87+
select n.Port);
88+
89+
portArray.Sort();
90+
91+
for (int i = startingPort; i < UInt16.MaxValue; i++)
92+
if (!portArray.Contains(i))
93+
return i;
94+
95+
return 0;
96+
}
97+
5998

60-
public static IPAddress GetBroadcastAddress(this IPAddress address, IPAddress subnetMask)
99+
public static IPAddress GetBroadcastAddress(this IPAddress address, IPAddress subnetMask)
61100
{
62101
byte[] ipAdressBytes = address.GetAddressBytes();
63102
byte[] subnetMaskBytes = subnetMask.GetAddressBytes();

windows/Properties/latest-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v:1.1.8489.35707
1+
v:1.1.8506.21097

windows/assets/app-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"frontDomain": "speed.cloudflare.com/__down?bytes=1000",
33
"scanDomain": "speed.cloudflare.com/__down?bytes=",
4-
"clientConfigUrl": "https://raw.githubusercontent.com/MortezaBashsiz/CFScanner/main/bash/ClientConfig.json"
4+
"clientConfigUrl": "https://raw.githubusercontent.com/MortezaBashsiz/CFScanner/main/config/ClientConfig.json"
55
}

windows/frmMain.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public frmMain()
6565
isAppCongigValid = false;
6666
}
6767

68+
69+
6870
scanEngine = new ScanEngine();
6971

7072
loadLastResultsComboList();
@@ -287,6 +289,11 @@ private void startStopScan(ScanType scanType = ScanType.SCAN_CLOUDFLARE_IPS)
287289
{
288290
scanFinished = true;
289291

292+
if (!scanEngine.progressInfo.pauseRequested)
293+
{
294+
lastScanType = null;
295+
}
296+
290297
// don't update results in diagnose test
291298
if (!isDiagnosing)
292299
currentScanResults = scanEngine.progressInfo.scanResults.workingIPs;

0 commit comments

Comments
 (0)