Пример #1
0
 protected override void OnIPNotify(IPNotifyItem stat)
 {
     if (PackageDirect.IN == stat.m_direct)
     {
         Console.WriteLine(
             "接受数据\t源地址:{0}\t\t目的地址:{1}\t\t包大小:{2}",
             stat.SourceIP, stat.DestIP, stat.m_len);
     }
     else
     {
         Console.WriteLine(
             "发送数据\t源地址:{0}\t\t目的地址:{1}\t\t包大小:{2}",
             stat.SourceIP, stat.DestIP, stat.m_len);
     }
 }
Пример #2
0
 protected override void OnIPNotify(IPNotifyItem stat)
 {
     m_ColorConsole.TextColor(Color.Red);
     if (PackageDirect.IN == stat.Director)
     {
         Console.WriteLine(
             "接受数据\t源地址:{0}\t\t目的地址:{1}\t\t包大小:{2}",
             stat.SourceIP, stat.DestIP, stat.Length);
     }
     else
     {
         m_ColorConsole.TextColor(Color.Green);
         Console.WriteLine(
             "发送数据\t源地址:{0}\t\t目的地址:{1}\t\t包大小:{2}",
             stat.SourceIP, stat.DestIP, stat.Length);
     }
 }
Пример #3
0
        void DoAnalyze(List<SocketPacket> packages, int ticklen)
        {
            NetSpeed speed = new NetSpeed();

            foreach (SocketPacket p in packages)
            {
                IPNotifyItem stat = new IPNotifyItem();
                stat.SourceIP = p.SourceAddress;
                stat.DestIP = p.DestinationAddress;
                stat.Length = p.TotalLength;
                stat.ProtocolType = p.ProtocolType;
                stat.MessageLength = p.MessageLength;
                stat.SourcePort = p.SourcePort;
                stat.DestPort = p.DestinationPort;

                if (IPAddress.Equals(p.SourceAddress, m_localbindaddress))
                {//Send  
                    speed.nUpTotalLen += p.TotalLength;
                    speed.nUppackageCnt += 1;
                    switch (p.ProtocolType)
                    {
                        case Protocol.TCP:
                            speed.nUpTCPTotalLen += p.TotalLength;
                            speed.nUpTCPpackageCnt += 1;
                            break;
                        case Protocol.UDP:
                            speed.nUpUDPTotalLen += p.TotalLength;
                            speed.nUpUDPpackageCnt += 1;
                            break;
                        case Protocol.ICMP:
                            speed.nUpICMPTotalLen += p.TotalLength;
                            speed.nUpICMPpackageCnt += 1;
                            break;
                        case Protocol.IGMP:
                            speed.nUpIGMPTotalLen += p.TotalLength;
                            speed.nUpIGMPpackageCnt += 1;
                            break;
                    }

                    stat.Director = PackageDirect.OUT;

                    if (m_ipnotify != null)
                        m_ipnotify.Invoke(stat);
                }
                else
                {//Receive  
                    speed.nDownTotalLen += p.TotalLength;
                    speed.nDownpackageCnt += 1;
                    switch (p.ProtocolType)
                    {
                        case Protocol.TCP:
                            speed.nDownTCPTotalLen += p.TotalLength;
                            speed.nDownTCPpackageCnt += 1;
                            break;
                        case Protocol.UDP:
                            speed.nDownUDPTotalLen += p.TotalLength;
                            speed.nDownUDPpackageCnt += 1;
                            break;
                        case Protocol.ICMP:
                            speed.nDownICMPTotalLen += p.TotalLength;
                            speed.nDownICMPpackageCnt += 1;
                            break;
                        case Protocol.IGMP:
                            speed.nDownIGMPTotalLen += p.TotalLength;
                            speed.nDownIGMPpackageCnt += 1;
                            break;
                    }

                    stat.Director = PackageDirect.IN;

                    if (m_ipnotify != null)
                        m_ipnotify.Invoke(stat);
                }
            }

            speed.CaculateSpeed(ticklen);
            if (m_speednotify != null)
                m_speednotify.Invoke(speed);
        }