示例#1
0
        private ProcessPort GetUDPProcessPort(UdpRow tr)
        {
            ProcessPort _pp = new ProcessPort()
            {
                LocalAddress  = tr.LocalAddress.ToString(),
                Port          = tr.LocalPort,
                RemoteAddress = "",
                Type          = ProtocolType.UDPType,
                RemotePort    = 0,
            };

            return(_pp);
        }
示例#2
0
 /// <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,
                     });
                 }
             }
         }
     }
     catch (Exception e)
     { }
 }
示例#3
0
        public static UdpRow[] GetUdpConnection()
        {
            UdpRow[]  array     = null;
            const int ipVersion = 2;
            var       cb        = 0;

            GetExtendedUdpTable(IntPtr.Zero, ref cb, true, ipVersion, UDP_TABLE_CLASS.UDP_TABLE_OWNER_PID);
            var intPtr = Marshal.AllocHGlobal(cb);

            try
            {
                var extendedUdpTable = GetExtendedUdpTable(intPtr, ref cb, true, ipVersion, UDP_TABLE_CLASS.UDP_TABLE_OWNER_PID);
                var flag             = extendedUdpTable > 0u;
                if (flag)
                {
                    return(null);
                }

                var udpTable = (UdpTable)Marshal.PtrToStructure(intPtr, typeof(UdpTable));
                var intPtr2  = (IntPtr)((long)intPtr + Marshal.SizeOf(udpTable.dwNumEntries));
                array = new UdpRow[udpTable.dwNumEntries];
                var num = 0;
                while (num < udpTable.dwNumEntries)
                {
                    var udpRow = (UdpRow)Marshal.PtrToStructure(intPtr2, typeof(UdpRow));
                    array[num] = udpRow;
                    intPtr2    = (IntPtr)((long)intPtr2 + Marshal.SizeOf(udpRow));
                    num++;
                }
            }
            catch (Exception)
            {
                // ignored
            }
            finally
            {
                Marshal.FreeHGlobal(intPtr);
            }
            return(array);
        }
示例#4
0
 private void AddUDPNetProcess(UdpRow item)
 {
     try
     {
         var _netProcess = netProcesses.FirstOrDefault(x => x.ProcessID == item.owningPid);
         if (_netProcess == null)
         {
             _netProcess = new NetProcess()
             {
                 ProcessID = item.owningPid, ProcessName = ProcessAPI.GetProcessNameByPID(item.owningPid)
             };
             netProcesses.Add(_netProcess);
         }
         if (_netProcess.Ports.FirstOrDefault(x => x.Port == item.LocalPort) == null)
         {
             _netProcess.ProcessICon = ProcessAPI.GetIcon(item.owningPid, true);
             _netProcess.Ports.Add(GetUDPProcessPort(item));
         }
     }
     catch (Exception e)
     {
     }
 }
示例#5
0
        public static UdpRow[] GetUdpConnection()
        {
            UdpRow[] array            = null;
            int      ipVersion        = 2;
            int      cb               = 0;
            uint     extendedUdpTable = GetExtendedUdpTable(IntPtr.Zero, ref cb, true, ipVersion, UDP_TABLE_CLASS.UDP_TABLE_OWNER_PID, 0u);
            IntPtr   intPtr           = Marshal.AllocHGlobal(cb);

            try
            {
                extendedUdpTable = GetExtendedUdpTable(intPtr, ref cb, true, ipVersion, UDP_TABLE_CLASS.UDP_TABLE_OWNER_PID, 0u);
                bool flag = extendedUdpTable > 0u;
                if (flag)
                {
                    return(null);
                }

                UdpTable udpTable = (UdpTable)Marshal.PtrToStructure(intPtr, typeof(UdpTable));
                IntPtr   intPtr2  = (IntPtr)((long)intPtr + Marshal.SizeOf(udpTable.dwNumEntries));
                array = new UdpRow[udpTable.dwNumEntries];
                int num = 0;
                while (num < (long)((ulong)udpTable.dwNumEntries))
                {
                    UdpRow udpRow = (UdpRow)Marshal.PtrToStructure(intPtr2, typeof(UdpRow));
                    array[num] = udpRow;
                    intPtr2    = (IntPtr)((long)intPtr2 + Marshal.SizeOf(udpRow));
                    num++;
                }
            }
            catch (Exception)
            { }
            finally
            {
                Marshal.FreeHGlobal(intPtr);
            }
            return(array);
        }