예제 #1
0
파일: NetHelper.cs 프로젝트: an1ju/Qi
        /// <summary>获取所有Tcp连接,带进程Id</summary>
        /// <returns></returns>
        public static TcpConnectionInformation2[] GetAllTcpConnections()
        {
            if (!Runtime.Windows)
            {
                return(new TcpConnectionInformation2[0]);
            }

            return(TcpConnectionInformation2.GetAllTcpConnections());
        }
예제 #2
0
        public void GetAllTcp()
        {
            var tcps = TcpConnectionInformation2.GetAllTcpConnections();

            Assert.NotNull(tcps);
            Assert.True(tcps.Length > 0);
            Assert.Contains(tcps, e => e.ProcessId > 0);

            foreach (var item in tcps)
            {
                XTrace.WriteLine("{0}\t{1}\t{2}\t{3}", item.LocalEndPoint, item.RemoteEndPoint, item.State, item.ProcessId);
            }
        }