Skip to content

Commit

Permalink
sth
Browse files Browse the repository at this point in the history
  • Loading branch information
mili-tan committed Dec 10, 2020
1 parent a6d87f6 commit 1ea4928
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Arashi.Aoi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
Expand Down Expand Up @@ -105,6 +107,7 @@ static void Main(string[] args)
Console.WriteLine("Failed to get $PORT Environment Variable");
}
if (PortIsUse(53)) Config.UpStream = IPAddress.Loopback.ToString();
if (upOption.HasValue()) Config.UpStream = upOption.Value();
if (timeoutOption.HasValue()) Config.TimeOut = timeoutOption.ParsedValue;
if (retriesOption.HasValue()) Config.Retries = retriesOption.ParsedValue;
Expand Down Expand Up @@ -228,5 +231,14 @@ static void Main(string[] args)
cmd.Execute();
}
}

public static bool PortIsUse(int port)
{
IPEndPoint[] ipEndPointsTcp = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners();
IPEndPoint[] ipEndPointsUdp = IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners();

return ipEndPointsTcp.Any(endPoint => endPoint.Port == port)
|| ipEndPointsUdp.Any(endPoint => endPoint.Port == port);
}
}
}

0 comments on commit 1ea4928

Please sign in to comment.