Example #1
0
        private static List <ProConnRecordBag> GetNetConn()
        {
            List <ProConnRecordBag> rec = new List <ProConnRecordBag>();

            TcpRow[] tlist = NetProcessAPI.GetAllTcpConnections();
            foreach (var item in tlist)
            {
                var pro = rec.FirstOrDefault(x => x.Name == item.owningPid.ToString());
                if (pro == null)
                {
                    pro = new ProConnRecordBag()
                    {
                        Name = item.owningPid.ToString(), Count = 0, Record = new List <ProConnRecord>()
                    };
                    rec.Add(pro);
                }
                var ipConn = pro.Record.FirstOrDefault(x => x.LI == item.LocalAddress.ToString() && x.RI == item.RemoteAddress.ToString());
                if (ipConn == null)
                {
                    ipConn = new ProConnRecord()
                    {
                        LI = item.LocalAddress.ToString(), RI = item.RemoteAddress.ToString(), Conn = new List <ProConnPort>()
                    };
                    pro.Record.Add(ipConn);
                }
                ipConn.Conn.Add(new ProConnPort()
                {
                    LP = item.LocalPort, RP = item.RemotePort, TP = ProtocolType.TCPType.ToString().Replace("Type", ""), Status = item.state.ToString()
                });
                pro.Count++;
            }
            UdpRow[] ulist = NetProcessAPI.GetAllUdpConnections();
            foreach (var item in ulist)
            {
                var pro = rec.FirstOrDefault(x => x.Name == item.owningPid.ToString());
                if (pro == null)
                {
                    pro = new ProConnRecordBag()
                    {
                        Name = item.owningPid.ToString(), Count = 0, Record = new List <ProConnRecord>()
                    };
                    rec.Add(pro);
                }
                var ipConn = pro.Record.FirstOrDefault(x => x.LI == item.LocalAddress.ToString());
                if (ipConn == null)
                {
                    ipConn = new ProConnRecord()
                    {
                        LI = item.LocalAddress.ToString(), Conn = new List <ProConnPort>()
                    };
                    pro.Record.Add(ipConn);
                }
                ipConn.Conn.Add(new ProConnPort()
                {
                    LP = item.LocalPort, TP = ProtocolType.TCPType.ToString().Replace("Type", "")
                });
                pro.Count++;
            }
            return(rec);
        }
Example #2
0
        public static void SendProConnRecord(NetProcess pro)
        {
            ProConnRecordBag rs = new ProConnRecordBag();

            rs.Name   = pro.ProcessName;
            rs.Count  = pro.Ports.Count();
            rs.Record = new List <ProConnRecord>();
            foreach (var p in pro.Ports)
            {
                var r = rs.Record.FirstOrDefault(x => x.LI == p.LocalAddress && x.RI == p.RemoteAddress);
                if (r != null)
                {
                    r.Conn.Add(new ProConnPort()
                    {
                        LP = p.Port,
                        RP = p.RemotePort,
                        TP = p.Type.ToString().Replace("Type", ""),
                    });
                }
                else
                {
                    var rcd = new ProConnRecord()
                    {
                        LI   = p.LocalAddress,
                        RI   = p.RemoteAddress,
                        Conn = new List <ProConnPort>(),
                    };
                    rcd.Conn.Add(new ProConnPort()
                    {
                        LP = p.Port,
                        RP = p.RemotePort,
                        TP = p.Type.ToString().Replace("Type", ""),
                    });
                    rs.Record.Add(rcd);
                }
            }
            try
            {
                string rsJson = JsonTool.ToStr(rs);
                string path   = R.Paths.BasePath + @"ProConnRec";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                //Write(string.Format(path + @"\{0}-{1}.txt", DateTime.Now.ToString("yyyyMMddHHmmss"), pro.ProcessName), rsJson);
                SendHelper.Send("43", rsJson);
            }
            catch { }
        }
Example #3
0
 public static void SendProConnRecord(ProConnRecordBag rec)
 {
     try
     {
         rec.Name = ProcessAPI.GetProcessNameByPID(int.Parse(rec.Name));
         if (!string.IsNullOrWhiteSpace(rec.Name) && rec.Name.ToLower() != "idle")
         {
             string rsJson = JsonTool.ToStr(rec);
             string path   = R.Paths.BasePath + @"ProConnRec";
             if (!Directory.Exists(path))
             {
                 Directory.CreateDirectory(path);
             }
             //Write(string.Format(path + @"\{0}-{1}.txt", DateTime.Now.ToString("yyyyMMddHHmmss"), rec.Name), rsJson);
             SendHelper.Send("43", rsJson);
         }
     }
     catch { }
 }