Skip to content

Commit 4f6b4cf

Browse files
committed
🚧 ACC
1 parent 1d85560 commit 4f6b4cf

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/BD.Common8.Bcl/Net/PortHelper.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,24 @@ public static bool IsUsePort(IPAddress address, int port)
4444
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4545
public static bool IsUsePort(int port)
4646
{
47+
#if ANDROID
48+
return IsUsePort(IPAddress.Loopback, port);
49+
#else
4750
try
4851
{
49-
return IPGlobalProperties.GetIPGlobalProperties()
50-
.GetActiveTcpListeners()
51-
.Any(x => x.Port == port);
52+
var ipGlobalProps = IPGlobalProperties.GetIPGlobalProperties();
53+
var tcp = ipGlobalProps.GetActiveTcpListeners();
54+
return tcp.Any(x => x.Port == port);
5255
}
5356
catch
5457
{
5558
return IsUsePort(IPAddress.Loopback, port);
5659
}
60+
#endif
5761
}
5862

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

0 commit comments

Comments
 (0)