|
|
@@ -85,21 +85,31 @@ namespace Shadowsocks.Controller |
|
|
|
|
|
|
|
private int GetFreePort()
|
|
|
|
{
|
|
|
|
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
|
|
|
|
IPEndPoint[] tcpEndPoints = properties.GetActiveTcpListeners();
|
|
|
|
|
|
|
|
List<int> usedPorts = new List<int>();
|
|
|
|
foreach (IPEndPoint endPoint in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners())
|
|
|
|
{
|
|
|
|
usedPorts.Add(endPoint.Port);
|
|
|
|
}
|
|
|
|
for (int port = 8123; port < 65535; port++)
|
|
|
|
int defaultPort = 8123;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (!usedPorts.Contains(port))
|
|
|
|
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
|
|
|
|
IPEndPoint[] tcpEndPoints = properties.GetActiveTcpListeners();
|
|
|
|
|
|
|
|
List<int> usedPorts = new List<int>();
|
|
|
|
foreach (IPEndPoint endPoint in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners())
|
|
|
|
{
|
|
|
|
usedPorts.Add(endPoint.Port);
|
|
|
|
}
|
|
|
|
for (int port = defaultPort; port < 65535; port++)
|
|
|
|
{
|
|
|
|
return port;
|
|
|
|
if (!usedPorts.Contains(port))
|
|
|
|
{
|
|
|
|
return port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
// in case access denied
|
|
|
|
Logging.LogUsefulException(e);
|
|
|
|
return defaultPort;
|
|
|
|
}
|
|
|
|
throw new Exception("No free port found.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|