Skip to content

Commit

Permalink
🚧 ACC
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed Mar 4, 2025
1 parent 1d85560 commit 4f6b4cf
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/BD.Common8.Bcl/Net/PortHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,24 @@ public static bool IsUsePort(IPAddress address, int port)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsUsePort(int port)
{
#if ANDROID
return IsUsePort(IPAddress.Loopback, port);
#else
try
{
return IPGlobalProperties.GetIPGlobalProperties()
.GetActiveTcpListeners()
.Any(x => x.Port == port);
var ipGlobalProps = IPGlobalProperties.GetIPGlobalProperties();
var tcp = ipGlobalProps.GetActiveTcpListeners();
return tcp.Any(x => x.Port == port);
}
catch
{
return IsUsePort(IPAddress.Loopback, port);
}
#endif
}

/// <summary>
/// 根据 TCP 端口号获取占用的进程
/// 根据 TCP 端口号获取占用的进程,当前仅支持 Windows 平台,其他平台将抛出 <see cref="PlatformNotSupportedException"/>,且会因目标进程为管理员权限时获取失败
/// </summary>
/// <param name="port"></param>
/// <returns></returns>
Expand Down

0 comments on commit 4f6b4cf

Please sign in to comment.