Beispiel #1
0
 public TcpViewModelDataType(TcpRow data, Image icon, string name, string path)
 {
     Data         = data;
     ProccessIcon = icon;
     ImageName    = name;
     FullPath     = path;
 }
Beispiel #2
0
 public TcpViewModelDataType(TcpRow data)
 {
     Data         = data;
     ProccessIcon = new Image();
     ImageName    = "Skipped";
     FullPath     = "Skipped";
 }
Beispiel #3
0
 public TaskItemDetailed(string processName, Int32 pid, TcpRow data, string processPath, Image processIcon)
 {
     ProcessName = processName;
     ProcessId   = pid;
     InnerData   = data;
     ProcessPath = processPath;
     ProcessIcon = processIcon;
 }
Beispiel #4
0
 private static string TcpRowToString(TcpRow rowInput)
 {
     return(String.Format(">{0}:{1} to {2}:{3} is {4} by 0x{5:x}",
                          (rowInput.localAddr & 0xFF) + "." + ((rowInput.localAddr & 0xFF00) >> 8) + "." + ((rowInput.localAddr & 0xFF0000) >> 16) + "." + ((rowInput.localAddr & 0xFF000000) >> 24),
                          ((rowInput.localPortInNetworkOrder & 0xFF00) >> 8) + ((rowInput.localPortInNetworkOrder & 0xFF) << 8),
                          (rowInput.remoteAddr & 0xFF) + "." + ((rowInput.remoteAddr & 0xFF00) >> 8) + "." + ((rowInput.remoteAddr & 0xFF0000) >> 16) + "." + ((rowInput.remoteAddr & 0xFF000000) >> 24),
                          ((rowInput.remotePortInNetworkOrder & 0xFF00) >> 8) + ((rowInput.remotePortInNetworkOrder & 0xFF) << 8),
                          rowInput.tcpState,
                          rowInput.owningPid));
 }
Beispiel #5
0
 /// <summary>
 /// 整理TCP连接到所属的进程
 /// </summary>
 /// <param name="t"></param>
 void SetNetProcessConnection(TcpRow t)
 {
     try
     {
         Process p = NowProcess.FirstOrDefault(x => x.Id == t.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        = t.LocalIP.ToString(),
                             LocalPort      = t.LocalPort,
                             RemoteIP       = t.RemoteIP.ToString(),
                             RemotePort     = t.RemotePort,
                             ProtocolName   = "TCP",
                             Status         = t.State,
                             LastUpdateTime = DateTime.Now,
                         }
                     },
                 });
             }
             else
             {
                 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)
     { }
 }
Beispiel #6
0
        private ProcessPort GetTcpProcessPort(TcpRow tr)
        {
            ProcessPort _pp = new ProcessPort()
            {
                LocalAddress  = tr.LocalAddress.ToString(),
                Port          = tr.LocalPort,
                RemoteAddress = tr.RemoteAddress.ToString(),
                Type          = ProtocolType.TCPType,
                RemotePort    = tr.RemotePort,
            };

            return(_pp);
        }
Beispiel #7
0
        private List <Connection> GetConnections(Process process)
        {
            var connections = new List <Connection>();

            IntPtr tcpTable       = IntPtr.Zero;
            int    tcpTableLength = 0;

            if (GetExtendedTcpTable(tcpTable, ref tcpTableLength, false, AddressFamily.InterNetwork, TCP_TABLE_OWNER_PID_CONNECTIONS, 0) != 0)
            {
                try
                {
                    tcpTable = Marshal.AllocHGlobal(tcpTableLength);
                    if (GetExtendedTcpTable(tcpTable, ref tcpTableLength, false, AddressFamily.InterNetwork, TCP_TABLE_OWNER_PID_CONNECTIONS, 0) == 0)
                    {
                        TcpTable table = (TcpTable)Marshal.PtrToStructure(tcpTable, typeof(TcpTable));

                        IntPtr rowPtr = tcpTable + Marshal.SizeOf(typeof(uint));
                        for (int i = 0; i < table.length; i++)
                        {
                            TcpRow row = (TcpRow)Marshal.PtrToStructure(rowPtr, typeof(TcpRow));

                            if (row.owningPid == process.Id)
                            {
                                IPEndPoint local  = new IPEndPoint(row.localAddr, (ushort)IPAddress.NetworkToHostOrder((short)row.localPort));
                                IPEndPoint remote = new IPEndPoint(row.remoteAddr, (ushort)IPAddress.NetworkToHostOrder((short)row.remotePort));

                                connections.Add(new Connection()
                                {
                                    localEndPoint = local, remoteEndPoint = remote
                                });
                            }

                            rowPtr = rowPtr + Marshal.SizeOf(typeof(TcpRow));
                        }
                    }
                }
                finally
                {
                    if (tcpTable != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(tcpTable);
                    }
                }
            }

            return(connections);
        }
        public void RemoveTcpRowItemFromObData(TcpRow tcpRow)
        {
            int  removeIndex = 0;
            bool isfinded    = false;

            for (int i = 0; i < ObData.Count; i++)
            {
                if (ObData[i].InnerData.Equals(tcpRow))
                {
                    isfinded    = true;
                    removeIndex = i;
                    break;
                }
            }
            if (isfinded)
            {
                ObData.Remove(ObData[removeIndex]);
            }
        }
Beispiel #9
0
        public static TcpRow[] GetTcpConnection()
        {
            TcpRow[]  array     = null;
            const int ipVersion = 2;
            var       cb        = 0;

            GetExtendedTcpTable(IntPtr.Zero, ref cb, true, ipVersion, TCP_TABLE_CLASS.TCP_TABLE_OWNER_PID_ALL);
            var intPtr = Marshal.AllocHGlobal(cb);

            try
            {
                var extendedTcpTable = GetExtendedTcpTable(intPtr, ref cb, true, ipVersion, TCP_TABLE_CLASS.TCP_TABLE_OWNER_PID_ALL);
                var flag             = extendedTcpTable > 0u;
                if (flag)
                {
                    return(null);
                }

                var tcpTable = (TcpTable)Marshal.PtrToStructure(intPtr, typeof(TcpTable));
                var intPtr2  = (IntPtr)((long)intPtr + Marshal.SizeOf(tcpTable.dwNumEntries));
                array = new TcpRow[tcpTable.dwNumEntries];
                var num = 0;
                while (num < tcpTable.dwNumEntries)
                {
                    var tcpRow = (TcpRow)Marshal.PtrToStructure(intPtr2, typeof(TcpRow));
                    array[num] = tcpRow;
                    intPtr2    = (IntPtr)((long)intPtr2 + Marshal.SizeOf(tcpRow));
                    num++;
                }
            }
            catch (Exception)
            {
                // ignored
            }
            finally
            {
                Marshal.FreeHGlobal(intPtr);
            }
            return(array);
        }
Beispiel #10
0
 private void AddTCPNetProcess(TcpRow 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(GetTcpProcessPort(item));
     }
     catch (Exception e)
     {
     }
 }
Beispiel #11
0
        public static TcpRow[] GetTcpConnection()
        {
            TcpRow[] array            = null;
            int      ipVersion        = 2;
            int      cb               = 0;
            uint     extendedTcpTable = GetExtendedTcpTable(IntPtr.Zero, ref cb, true, ipVersion, TCP_TABLE_CLASS.TCP_TABLE_OWNER_PID_ALL, 0u);
            IntPtr   intPtr           = Marshal.AllocHGlobal(cb);

            try
            {
                extendedTcpTable = GetExtendedTcpTable(intPtr, ref cb, true, ipVersion, TCP_TABLE_CLASS.TCP_TABLE_OWNER_PID_ALL, 0u);
                bool flag = extendedTcpTable > 0u;
                if (flag)
                {
                    return(null);
                }

                TcpTable tcpTable = (TcpTable)Marshal.PtrToStructure(intPtr, typeof(TcpTable));
                IntPtr   intPtr2  = (IntPtr)((long)intPtr + Marshal.SizeOf(tcpTable.dwNumEntries));
                array = new TcpRow[tcpTable.dwNumEntries];
                int num = 0;
                while (num < (long)((ulong)tcpTable.dwNumEntries))
                {
                    TcpRow tcpRow = (TcpRow)Marshal.PtrToStructure(intPtr2, typeof(TcpRow));
                    array[num] = tcpRow;
                    intPtr2    = (IntPtr)((long)intPtr2 + Marshal.SizeOf(tcpRow));
                    num++;
                }
            }
            catch (Exception)
            { }
            finally
            {
                Marshal.FreeHGlobal(intPtr);
            }
            return(array);
        }
 public void AddItem(TcpRow item)
 {
     _tcpRows.Add(item.GetHashCode(), item);
 }
 public bool IsObDataContains(TcpRow tcpRow)
 {
     return(ObData.Any(taskItemDetailed => taskItemDetailed.InnerData.Equals(tcpRow)));
 }