File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff 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>
You can’t perform that action at this time.
0 commit comments