ソースを参照

更新网络流量监测(添加网络连接详情列表)

yuzhengyang 8 年 前
コミット
f040d78a37

+ 57 - 40
Fork.Net/Oreo.Plugins/Oreo.NetMan/Views/NetDetailForm.Designer.cs

@@ -28,14 +28,15 @@
         /// </summary>
         private void InitializeComponent()
         {
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
+            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle();
             System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle9 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle16 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle10 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle11 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle12 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle13 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle14 = new System.Windows.Forms.DataGridViewCellStyle();
-            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle15 = new System.Windows.Forms.DataGridViewCellStyle();
             this.label2 = new System.Windows.Forms.Label();
             this.label1 = new System.Windows.Forms.Label();
             this.DgProcessDetail = new System.Windows.Forms.DataGridView();
@@ -51,7 +52,7 @@
             this.tabPage1 = new System.Windows.Forms.TabPage();
             this.tabPage2 = new System.Windows.Forms.TabPage();
             this.DgvConnList = new System.Windows.Forms.DataGridView();
-            this.DgvConnListIcon = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.DgvConnListIcon = new System.Windows.Forms.DataGridViewImageColumn();
             this.DgvConnListProcess = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.DgvConnListProtocol = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.DgvConnListLocalIP = new System.Windows.Forms.DataGridViewTextBoxColumn();
@@ -92,14 +93,14 @@
             this.DgProcessDetail.AllowUserToResizeRows = false;
             this.DgProcessDetail.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
             this.DgProcessDetail.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.None;
-            dataGridViewCellStyle9.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            dataGridViewCellStyle9.BackColor = System.Drawing.SystemColors.Control;
-            dataGridViewCellStyle9.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            dataGridViewCellStyle9.ForeColor = System.Drawing.SystemColors.WindowText;
-            dataGridViewCellStyle9.SelectionBackColor = System.Drawing.SystemColors.Highlight;
-            dataGridViewCellStyle9.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
-            dataGridViewCellStyle9.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
-            this.DgProcessDetail.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle9;
+            dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control;
+            dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
+            dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
+            dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
+            dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
+            this.DgProcessDetail.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
             this.DgProcessDetail.ColumnHeadersHeight = 40;
             this.DgProcessDetail.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
             this.DgProcessDetail.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
@@ -110,14 +111,14 @@
             this.CoDownloadCount,
             this.CoUploadCount,
             this.CoConnectionCount});
-            dataGridViewCellStyle16.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
-            dataGridViewCellStyle16.BackColor = System.Drawing.SystemColors.Window;
-            dataGridViewCellStyle16.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            dataGridViewCellStyle16.ForeColor = System.Drawing.SystemColors.ControlText;
-            dataGridViewCellStyle16.SelectionBackColor = System.Drawing.SystemColors.GradientActiveCaption;
-            dataGridViewCellStyle16.SelectionForeColor = System.Drawing.Color.Black;
-            dataGridViewCellStyle16.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
-            this.DgProcessDetail.DefaultCellStyle = dataGridViewCellStyle16;
+            dataGridViewCellStyle8.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
+            dataGridViewCellStyle8.BackColor = System.Drawing.SystemColors.Window;
+            dataGridViewCellStyle8.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            dataGridViewCellStyle8.ForeColor = System.Drawing.SystemColors.ControlText;
+            dataGridViewCellStyle8.SelectionBackColor = System.Drawing.SystemColors.GradientActiveCaption;
+            dataGridViewCellStyle8.SelectionForeColor = System.Drawing.Color.Black;
+            dataGridViewCellStyle8.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
+            this.DgProcessDetail.DefaultCellStyle = dataGridViewCellStyle8;
             this.DgProcessDetail.Location = new System.Drawing.Point(0, 0);
             this.DgProcessDetail.Name = "DgProcessDetail";
             this.DgProcessDetail.ReadOnly = true;
@@ -135,48 +136,48 @@
             // 
             // CoName
             // 
-            dataGridViewCellStyle10.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            this.CoName.DefaultCellStyle = dataGridViewCellStyle10;
+            dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            this.CoName.DefaultCellStyle = dataGridViewCellStyle2;
             this.CoName.HeaderText = "";
             this.CoName.Name = "CoName";
             this.CoName.ReadOnly = true;
             // 
             // CoDownload
             // 
-            dataGridViewCellStyle11.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
-            this.CoDownload.DefaultCellStyle = dataGridViewCellStyle11;
+            dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
+            this.CoDownload.DefaultCellStyle = dataGridViewCellStyle3;
             this.CoDownload.HeaderText = "下载速度";
             this.CoDownload.Name = "CoDownload";
             this.CoDownload.ReadOnly = true;
             // 
             // CoUpload
             // 
-            dataGridViewCellStyle12.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
-            this.CoUpload.DefaultCellStyle = dataGridViewCellStyle12;
+            dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
+            this.CoUpload.DefaultCellStyle = dataGridViewCellStyle4;
             this.CoUpload.HeaderText = "上传速度";
             this.CoUpload.Name = "CoUpload";
             this.CoUpload.ReadOnly = true;
             // 
             // CoDownloadCount
             // 
-            dataGridViewCellStyle13.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
-            this.CoDownloadCount.DefaultCellStyle = dataGridViewCellStyle13;
+            dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
+            this.CoDownloadCount.DefaultCellStyle = dataGridViewCellStyle5;
             this.CoDownloadCount.HeaderText = "已下载流量";
             this.CoDownloadCount.Name = "CoDownloadCount";
             this.CoDownloadCount.ReadOnly = true;
             // 
             // CoUploadCount
             // 
-            dataGridViewCellStyle14.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
-            this.CoUploadCount.DefaultCellStyle = dataGridViewCellStyle14;
+            dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
+            this.CoUploadCount.DefaultCellStyle = dataGridViewCellStyle6;
             this.CoUploadCount.HeaderText = "已上传流量";
             this.CoUploadCount.Name = "CoUploadCount";
             this.CoUploadCount.ReadOnly = true;
             // 
             // CoConnectionCount
             // 
-            dataGridViewCellStyle15.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
-            this.CoConnectionCount.DefaultCellStyle = dataGridViewCellStyle15;
+            dataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            this.CoConnectionCount.DefaultCellStyle = dataGridViewCellStyle7;
             this.CoConnectionCount.HeaderText = "连接数";
             this.CoConnectionCount.Name = "CoConnectionCount";
             this.CoConnectionCount.ReadOnly = true;
@@ -228,7 +229,20 @@
             // 
             this.DgvConnList.AllowUserToAddRows = false;
             this.DgvConnList.AllowUserToDeleteRows = false;
-            this.DgvConnList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+            this.DgvConnList.AllowUserToResizeColumns = false;
+            this.DgvConnList.AllowUserToResizeRows = false;
+            this.DgvConnList.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
+            this.DgvConnList.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.None;
+            dataGridViewCellStyle9.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
+            dataGridViewCellStyle9.BackColor = System.Drawing.SystemColors.Control;
+            dataGridViewCellStyle9.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            dataGridViewCellStyle9.ForeColor = System.Drawing.SystemColors.WindowText;
+            dataGridViewCellStyle9.SelectionBackColor = System.Drawing.SystemColors.Highlight;
+            dataGridViewCellStyle9.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
+            dataGridViewCellStyle9.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
+            this.DgvConnList.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle9;
+            this.DgvConnList.ColumnHeadersHeight = 40;
+            this.DgvConnList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
             this.DgvConnList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
             this.DgvConnListIcon,
             this.DgvConnListProcess,
@@ -242,7 +256,8 @@
             this.DgvConnList.Name = "DgvConnList";
             this.DgvConnList.ReadOnly = true;
             this.DgvConnList.RowHeadersVisible = false;
-            this.DgvConnList.RowTemplate.Height = 23;
+            this.DgvConnList.RowTemplate.Height = 40;
+            this.DgvConnList.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
             this.DgvConnList.Size = new System.Drawing.Size(811, 468);
             this.DgvConnList.TabIndex = 0;
             // 
@@ -251,13 +266,15 @@
             this.DgvConnListIcon.HeaderText = "进程";
             this.DgvConnListIcon.Name = "DgvConnListIcon";
             this.DgvConnListIcon.ReadOnly = true;
-            this.DgvConnListIcon.Width = 108;
+            this.DgvConnListIcon.Resizable = System.Windows.Forms.DataGridViewTriState.True;
+            this.DgvConnListIcon.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
             // 
             // DgvConnListProcess
             // 
             this.DgvConnListProcess.HeaderText = "";
             this.DgvConnListProcess.Name = "DgvConnListProcess";
             this.DgvConnListProcess.ReadOnly = true;
+            this.DgvConnListProcess.Resizable = System.Windows.Forms.DataGridViewTriState.True;
             // 
             // DgvConnListProtocol
             // 
@@ -331,7 +348,7 @@
         private System.Windows.Forms.TabPage tabPage1;
         private System.Windows.Forms.TabPage tabPage2;
         private System.Windows.Forms.DataGridView DgvConnList;
-        private System.Windows.Forms.DataGridViewTextBoxColumn DgvConnListIcon;
+        private System.Windows.Forms.DataGridViewImageColumn DgvConnListIcon;
         private System.Windows.Forms.DataGridViewTextBoxColumn DgvConnListProcess;
         private System.Windows.Forms.DataGridViewTextBoxColumn DgvConnListProtocol;
         private System.Windows.Forms.DataGridViewTextBoxColumn DgvConnListLocalIP;

+ 31 - 32
Fork.Net/Oreo.Plugins/Oreo.NetMan/Views/NetDetailForm.cs

@@ -31,10 +31,8 @@ namespace Oreo.NetMan.Views
                 {
                     if (R.NFS.IsNetFlowRun || R.NFS.IsNetPacketRun)
                     {
-                        //R.Log.v("IsNetFlowRun: " + R.NFS.IsNetFlowRun + " IsNetPacketRun: " + R.NFS.IsNetPacketRun +
-                        //    " Upload: " + R.NFS.NetFlow.UploadData + " Download: " + R.NFS.NetFlow.DownloadData);
                         UIDgProcessDetailUpdate();
-                        //UIDgConnectDetailUpdate();
+                        UIDgConnectDetailUpdate();
                     }
                     Thread.Sleep(1000);
                 }
@@ -63,7 +61,7 @@ namespace Oreo.NetMan.Views
                                 r.Cells["CoUpload"].Value = ByteConvertTool.Fmt(p.UploadData);
                                 r.Cells["CoDownloadCount"].Value = ByteConvertTool.Fmt(p.DownloadDataCount);
                                 r.Cells["CoUploadCount"].Value = ByteConvertTool.Fmt(p.UploadDataCount);
-                                r.Cells["CoConnectionCount"].Value = p.ConnectCount;
+                                r.Cells["CoConnectionCount"].Value = p.NetConnectionInfoList.Count();
                             }
                         }
                         if (!isUpdate)
@@ -84,45 +82,46 @@ namespace Oreo.NetMan.Views
 
             BeginInvoke(new Action(() =>
             {
-                if (R.NFS != null && ListTool.HasElements(R.NFS.NetConnectionInfoList))
+                if (R.NFS != null && ListTool.HasElements(R.NFS.NetProcessInfoList))
                 {
-                    R.NFS.NetConnectionInfoList.ForEach(conn =>
+                    R.NFS.NetProcessInfoList.ForEach(p =>
                     {
-                        try
+                        if (ListTool.HasElements(p.NetConnectionInfoList) && p.ProcessIcon != null)
                         {
-                            Process p = Process.GetProcessById(conn.ProcessId);
-                            bool isUpdate = false;
-                            foreach (DataGridViewRow r in DgvConnList.Rows)
+                            p.NetConnectionInfoList.ForEach(conn =>
                             {
-                                if (r.Cells["DgvConnListProcess"].Value.ToString() == p.ProcessName &&
-                                    r.Cells["DgvConnListLocalIP"].Value.ToString() == conn.LocalIP &&
-                                    r.Cells["DgvConnListLocalPort"].Value.ToString() == conn.LocalPort.ToString())
+                                try
                                 {
-                                    isUpdate = true;
-                                    r.Cells["DgvConnListIcon"].Value = ProcessInfoTool.GetIcon(p, false);
-                                    r.Cells["DgvConnListProcess"].Value = p.ProcessName;
-                                    r.Cells["DgvConnListProtocol"].Value = conn.ProtocolName;
-                                    r.Cells["DgvConnListLocalIP"].Value = conn.LocalIP;
-                                    r.Cells["DgvConnListLocalPort"].Value = conn.LocalPort;
-                                    r.Cells["DgvConnListRemoteIP"].Value = conn.RemoteIP;
-                                    r.Cells["DgvConnListRemotePort"].Value = conn.RemotePort;
-                                    r.Cells["DgvConnListStatus"].Value = conn.Status;
+                                    bool isUpdate = false;
+                                    foreach (DataGridViewRow r in DgvConnList.Rows)
+                                    {
+                                        if (r.Cells["DgvConnListProcess"].Value.ToString() == p.ProcessName &&
+                                            r.Cells["DgvConnListLocalIP"].Value.ToString() == conn.LocalIP &&
+                                            r.Cells["DgvConnListLocalPort"].Value.ToString() == conn.LocalPort.ToString())
+                                        {
+                                            isUpdate = true;
+                                            r.Cells["DgvConnListProtocol"].Value = conn.ProtocolName;
+                                            r.Cells["DgvConnListLocalIP"].Value = conn.LocalIP;
+                                            r.Cells["DgvConnListLocalPort"].Value = conn.LocalPort;
+                                            r.Cells["DgvConnListRemoteIP"].Value = conn.RemoteIP;
+                                            r.Cells["DgvConnListRemotePort"].Value = conn.RemotePort;
+                                            r.Cells["DgvConnListStatus"].Value = conn.Status;
+                                        }
+                                    }
+                                    if (!isUpdate)
+                                    {
+                                        DgvConnList.Rows.Add(new object[] {
+                                        p.ProcessIcon, p.ProcessName, conn.ProtocolName,
+                                        conn.LocalIP, conn.LocalPort, conn.RemoteIP, conn.RemotePort, conn.Status
+                                    });
+                                    }
                                 }
-                            }
-                            if (!isUpdate)
-                            {
-                                DgvConnList.Rows.Add(new object[] {
-                                 ProcessInfoTool.GetIcon(p, false), p.ProcessName, conn.ProtocolName,
-                                 conn.LocalIP, conn.LocalPort, conn.RemoteIP, conn.RemotePort, conn.Status
+                                catch (Exception e) { }
                             });
-                            }
                         }
-                        catch (Exception e) { }
                     });
                 }
             }));
         }
-
-
     }
 }

+ 23 - 2
Fork.Net/Y.Utils/IOUtils/FileUtils/FilePackageTool.cs

@@ -14,6 +14,7 @@ using System.Linq;
 using System.Resources;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.Text;
+using Y.Utils.DataUtils.Collections;
 
 namespace Y.Utils.IOUtils.FileUtils
 {
@@ -142,7 +143,27 @@ namespace Y.Utils.IOUtils.FileUtils
         {
             DateTime beginTime = DateTime.Now;
             if (!Directory.Exists(srcPath)) return -11; //要打包的路径不存在
-            if (File.Exists(dstFile) && !overwrite) return -12;//加密后的目标文件已存在
+            if (File.Exists(dstFile) && !overwrite) return -12;//打包后的目标文件已存在
+
+            List<string> allfile = FileTool.GetAllFile(srcPath);
+            if (ListTool.HasElements(allfile))
+            {
+                using (FileStream fsWrite = new FileStream(dstFile, FileMode.Create))
+                {
+                    allfile.ForEach(x =>
+                    {
+                        using (FileStream fsRead = new FileStream(x, FileMode.Open))
+                        {
+                            fsRead.Close();
+                        }
+                    });
+                    fsWrite.Close();
+                }
+            }
+            else
+            {
+                return -13;//要打包的路径中没有文件
+            }
 
             return (int)Math.Ceiling((DateTime.Now - beginTime).TotalSeconds);//操作成功
         }
@@ -150,7 +171,7 @@ namespace Y.Utils.IOUtils.FileUtils
         /// 解包
         /// </summary>
         /// <returns></returns>
-        public static int UnPack(string srcFile, string dstPath, bool overwrite = true)
+        public static int Unpack(string srcFile, string dstPath, bool overwrite = true)
         {
             DateTime beginTime = DateTime.Now;
             if (!File.Exists(srcFile)) return -11; //要解包的文件不存在

+ 3 - 2
Fork.Net/Y.Utils/NetUtils/NetManUtils/NetConnectionInfo.cs

@@ -1,16 +1,17 @@
-using System.Data;
+using System;
+using System.Data;
 using System.Drawing;
 
 namespace Y.Utils.NetUtils.NetManUtils
 {
     public class NetConnectionInfo
     {
-        public int ProcessId { get; set; }
         public string ProtocolName { get; set; }
         public string LocalIP { get; set; }
         public int LocalPort { get; set; }
         public string RemoteIP { get; set; }
         public int RemotePort { get; set; }
         public ConnectionState Status { get; set; }
+        public DateTime LastUpdateTime { get; set; }
     }
 }

+ 85 - 9
Fork.Net/Y.Utils/NetUtils/NetManUtils/NetFlowService.cs

@@ -14,6 +14,7 @@ using Y.Utils.AppUtils;
 using Y.Utils.DataUtils.Collections;
 using Y.Utils.NetUtils.NetInfoUtils;
 using Y.Utils.WindowsUtils.ProcessUtils;
+using static Y.Utils.NetUtils.NetInfoUtils.NetProcessTool;
 
 namespace Y.Utils.NetUtils.NetManUtils
 {
@@ -225,7 +226,7 @@ namespace Y.Utils.NetUtils.NetManUtils
             if (ListTool.HasElements(NetProcessInfoList))
                 NetProcessInfoList.ForEach(x =>
                 {
-                    x.ConnectCount = 0;
+                    x.NetConnectionInfoList = new List<NetConnectionInfo>();
                 });
 
             // 统计TCP连接数
@@ -233,7 +234,7 @@ namespace Y.Utils.NetUtils.NetManUtils
             {
                 foreach (var t in TcpConnection)
                 {
-                    SetNetProcessConnection(t.ProcessId);
+                    SetNetProcessConnection(t);
                 }
             }
             // 统计UDP连接数
@@ -241,19 +242,19 @@ namespace Y.Utils.NetUtils.NetManUtils
             {
                 foreach (var u in UdpConnection)
                 {
-                    SetNetProcessConnection(u.ProcessId);
+                    SetNetProcessConnection(u);
                 }
             }
         }
         /// <summary>
-        /// 整理连接到所属的进程
+        /// 整理TCP连接到所属的进程
         /// </summary>
-        /// <param name="pid"></param>
-        void SetNetProcessConnection(int pid)
+        /// <param name="t"></param>
+        void SetNetProcessConnection(TcpRow t)
         {
             try
             {
-                Process p = NowProcess.FirstOrDefault(x => x.Id == pid);
+                Process p = NowProcess.FirstOrDefault(x => x.Id == t.ProcessId);
                 if (p != null)
                 {
                     var ppl = NetProcessInfoList.FirstOrDefault(x => x.ProcessName == p.ProcessName);
@@ -262,16 +263,91 @@ namespace Y.Utils.NetUtils.NetManUtils
                         NetProcessInfoList.Add(
                             new NetProcessInfo()
                             {
+                                ProcessId = p.Id,
                                 ProcessIcon = ProcessInfoTool.GetIcon(p, false),
                                 ProcessName = p.ProcessName,
-                                ConnectCount = 1,
                                 LastUpdateTime = DateTime.Now,
+                                NetConnectionInfoList = new List<NetConnectionInfo>() {
+                                    new NetConnectionInfo() {
+                                        LocalIP = t.LocalIP.ToString(),
+                                        LocalPort = t.LocalPort,
+                                        RemoteIP = t.RemoteIP.ToString(),
+                                        RemotePort = t.RemotePort,
+                                        ProtocolName = "TCP",
+                                        Status = t.State,
+                                        LastUpdateTime = DateTime.Now,
+                                    }
+                                },
                             });
                     }
                     else
                     {
-                        ppl.ConnectCount++;
                         ppl.LastUpdateTime = DateTime.Now;
+                        var conn = ppl.NetConnectionInfoList.FirstOrDefault(x => x.LocalIP == t.LocalIP.ToString() && x.LocalPort == t.LocalPort && x.RemoteIP == t.RemoteIP.ToString() && x.RemotePort == t.RemotePort);
+                        if (conn == null)
+                        {
+                            ppl.NetConnectionInfoList.Add(new NetConnectionInfo()
+                            {
+                                LocalIP = t.LocalIP.ToString(),
+                                LocalPort = t.LocalPort,
+                                RemoteIP = t.RemoteIP.ToString(),
+                                RemotePort = t.RemotePort,
+                                ProtocolName = "TCP",
+                                Status = t.State,
+                                LastUpdateTime = DateTime.Now,
+                            });
+                        }
+                    }
+                }
+            }
+            catch (Exception e)
+            { }
+        }
+        /// <summary>
+        /// 整理UDP连接到所属的进程
+        /// </summary>
+        /// <param name="u"></param>
+        void SetNetProcessConnection(UdpRow u)
+        {
+            try
+            {
+                Process p = NowProcess.FirstOrDefault(x => x.Id == u.ProcessId);
+                if (p != null)
+                {
+                    var ppl = NetProcessInfoList.FirstOrDefault(x => x.ProcessName == p.ProcessName);
+                    if (ppl == null)
+                    {
+                        NetProcessInfoList.Add(
+                            new NetProcessInfo()
+                            {
+                                ProcessId = p.Id,
+                                ProcessIcon = ProcessInfoTool.GetIcon(p, false),
+                                ProcessName = p.ProcessName,
+                                LastUpdateTime = DateTime.Now,
+                                NetConnectionInfoList = new List<NetConnectionInfo>() {
+                                    new NetConnectionInfo() {
+                                        LocalIP = u.LocalIP.ToString(),
+                                        LocalPort = u.LocalPort,
+                                        ProtocolName = "UDP",
+                                        LastUpdateTime = DateTime.Now,
+                                    }
+                                },
+                            });
+                    }
+                    else
+                    {
+                        ppl.LastUpdateTime = DateTime.Now;
+                        var conn = ppl.NetConnectionInfoList.FirstOrDefault(x => x.LocalIP == u.LocalIP.ToString() && x.LocalPort == u.LocalPort);
+                        if (conn == null)
+                        {
+                            ppl.NetConnectionInfoList.Add(new NetConnectionInfo()
+                            {
+                                LocalIP = u.LocalIP.ToString(),
+                                LocalPort = u.LocalPort,
+                                ProtocolName = "UDP",
+                                LastUpdateTime = DateTime.Now,
+                            });
+                        }
                     }
                 }
             }

+ 3 - 1
Fork.Net/Y.Utils/NetUtils/NetManUtils/NetProcessInfo.cs

@@ -1,10 +1,12 @@
 using System;
+using System.Collections.Generic;
 using System.Drawing;
 
 namespace Y.Utils.NetUtils.NetManUtils
 {
     public class NetProcessInfo
     {
+        public int ProcessId { get; set; }
         public string ProcessName { get; set; }
         public Icon ProcessIcon { get; set; }
         public DateTime LastUpdateTime { get; set; }
@@ -16,6 +18,6 @@ namespace Y.Utils.NetUtils.NetManUtils
         public int DownloadBag { get; set; }
         public long UploadBagCount { get; set; }
         public long DownloadBagCount { get; set; }
-        public int ConnectCount { get; set; }
+        public List<NetConnectionInfo> NetConnectionInfoList { get; set; }
     }
 }