Example #1
0
        public void Start()
        {
            #region 启动系统性能计数器统计
            try
            {
                NetFlow.Start();
                NetFlow.DataMonitorEvent += DataMonitorEvent;
                _IsNetFlowRun             = true;
            }
            catch { }
            #endregion

            #region 启动Socket包统计
            if (PermissionTool.IsAdmin())
            {
                List <IPAddress> hosts = NetCardInfoTool.GetIPv4Address();
                AllIPv4Address = NetCardInfoTool.GetAllIPv4Address();
                foreach (var host in hosts)
                {
                    try
                    {
                        NetPacketTool p = new NetPacketTool(host);
                        p.NewPacket += new NewPacketEventHandler(NewPacketEvent);
                        p.Start();
                        NetPacketList.Add(p);
                    }
                    catch { }
                }
                if (ListTool.HasElements(NetPacketList))
                {
                    _IsNetPacketRun = true;
                }
            }
            #endregion
        }
Example #2
0
        private void TestForm_Load(object sender, EventArgs e)
        {
            nft.Start();
            nft.DataMonitorEvent += DataMonitorEvent;

            List <IPAddress> hosts = NetCardInfoTool.GetIPv4Address();

            foreach (var host in hosts)
            {
                NetPacketTool p = new NetPacketTool(host);
                p.NewPacket += new NewPacketEventHandler(OnNewPacket);
                p.Start();
                npt.Add(p);
            }
        }
Example #3
0
        private void CheckRestart()
        {
            bool rest = false;

            string[] ints = NetCardInfoTool.GetInstanceNames();
            if (ListTool.IsNullOrEmpty(NetFlow.Instances) && ListTool.HasElements(ints))
            {
                rest = true;
            }
            if (ListTool.HasElements(NetFlow.Instances) && ListTool.HasElements(ints) &&
                string.Join("-", NetFlow.Instances) != string.Join("-", ints))
            {
                rest = true;
            }

            if (rest)
            {
                //重启 系统性能计数器
                NetFlow.Restart();
                //重启 抓包监听
                List <IPAddress> hosts = NetCardInfoTool.GetIPv4Address();
                AllIPv4Address = NetCardInfoTool.GetAllIPv4Address();
                foreach (var host in hosts)
                {
                    try
                    {
                        if (!NetPacketList.Any(x => x.IP.ToString() == host.ToString()))
                        {
                            NetPacketTool p = new NetPacketTool(host);
                            p.NewPacket += new NewPacketEventHandler(NewPacketEvent);
                            p.Start();
                            NetPacketList.Add(p);
                        }
                    }
                    catch { }
                }
            }
        }