Improve speedtest

pull/2148/head
2dust 2022-03-17 19:07:06 +08:00
parent 6408d51c85
commit 291fd491ff
4 changed files with 52 additions and 14 deletions

View File

@ -125,11 +125,11 @@ namespace v2rayN.Handler
List<Task> tasks = new List<Task>();
foreach (var it in _selecteds)
{
if (it.configType == (int)EConfigType.Custom)
if (!it.allowTest)
{
continue;
}
if (it.port <= 0)
if (it.configType == (int)EConfigType.Custom)
{
continue;
}
@ -222,11 +222,11 @@ namespace v2rayN.Handler
var timeout = 10;
foreach (var it in _selecteds)
{
if (it.configType == (int)EConfigType.Custom)
if (!it.allowTest)
{
continue;
}
if (it.port <= 0)
if (it.configType == (int)EConfigType.Custom)
{
continue;
}

View File

@ -1440,6 +1440,13 @@ namespace v2rayN.Handler
{
continue;
}
if (it.configType == (int)EConfigType.Vmess || it.configType == (int)EConfigType.VLESS)
{
if (!Utils.IsGuidByParse(configCopy.GetVmessItem(it.indexId).id))
{
continue;
}
}
//find unuse port
var port = httpPort;
@ -1461,6 +1468,7 @@ namespace v2rayN.Handler
continue;
}
it.port = port;
it.allowTest = true;
Inbounds inbound = new Inbounds
{

View File

@ -21,5 +21,9 @@ namespace v2rayN.Mode
{
get; set;
}
public bool allowTest
{
get; set;
}
}
}

View File

@ -22,6 +22,7 @@ using v2rayN.Base;
using Newtonsoft.Json.Linq;
using System.Web;
using log4net;
using System.Linq;
namespace v2rayN
{
@ -748,20 +749,26 @@ namespace v2rayN
public static bool PortInUse(int port)
{
bool inUse = false;
IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners();
var lstIpEndPoints = new List<IPEndPoint>(IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners());
foreach (IPEndPoint endPoint in ipEndPoints)
try
{
if (endPoint.Port == port)
IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners();
var lstIpEndPoints = new List<IPEndPoint>(IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners());
foreach (IPEndPoint endPoint in ipEndPoints)
{
inUse = true;
break;
if (endPoint.Port == port)
{
inUse = true;
break;
}
}
}
catch (Exception ex)
{
SaveLog(ex.Message, ex);
}
return inUse;
}
#endregion
@ -912,6 +919,25 @@ namespace v2rayN
return fileName;
}
public static IPAddress GetDefaultGateway()
{
return NetworkInterface
.GetAllNetworkInterfaces()
.Where(n => n.OperationalStatus == OperationalStatus.Up)
.Where(n => n.NetworkInterfaceType != NetworkInterfaceType.Loopback)
.SelectMany(n => n.GetIPProperties()?.GatewayAddresses)
.Select(g => g?.Address)
.Where(a => a != null)
// .Where(a => a.AddressFamily == AddressFamily.InterNetwork)
// .Where(a => Array.FindIndex(a.GetAddressBytes(), b => b != 0) >= 0)
.FirstOrDefault();
}
public static bool IsGuidByParse(string strSrc)
{
return Guid.TryParse(strSrc, out Guid g);
}
#endregion
#region TempPath