Пример #1
0
 public void InsertAllTable(PacketSimpInfo packetSimpInfo
                            , PacketCompInfo packetCompInfo
                            , PacketInfo packetInfo
                            , RealTimeInfo realTimeInfo)
 {
     using (db = dbFactory.Open())
     {
         db.Insert <PacketSimpInfo>(packetSimpInfo);
         db.Insert <PacketCompInfo>(packetCompInfo);
         db.Insert <PacketInfo>(packetInfo);
         db.Insert <RealTimeInfo>(realTimeInfo);
     }
 }
Пример #2
0
 public bool InsertCompPcap(PacketCompInfo packetCompInfo)
 {
     using (db = dbFactory.Open())
     {
         try
         {
             var flag = db.Insert <PacketCompInfo>(packetCompInfo);
             if (flag >= 0)
             {
                 return(true);
             }
         }
         catch (Exception)
         {
         }
         return(false);
     }
 }
Пример #3
0
        private void packetList_SelectionChanged(object sender, C1.WPF.DataGrid.DataGridSelectionChangedEventArgs e)
        {
            //foreach(var treeItem in treeviewPacket.Items)
            //{
            //    ((TreeViewItem)treeItem).Items.Clear();
            //}
            int index = packetList.SelectedIndex;

            if (index < 0)
            {
                return;
            }
            PacketCompInfo packetCompInfo = packetCompInfos[index : index];
            int            No             = packetCompInfo.No;
            int            frameNum       = packetCompInfo.FrameNum;
            int            framelentgh    = packetCompInfo.Framelentgh;
            int            capturelength  = packetCompInfo.Capturelength;
            string         sourceMac      = packetCompInfo.SourceMac;
            string         destMac        = packetCompInfo.DestMac;
            string         type           = packetCompInfo.Type;
            string         source         = packetCompInfo.Source;
            string         dest           = packetCompInfo.Dest;
            int            sourcePort     = packetCompInfo.SourcePort;
            int            destPort       = packetCompInfo.DestPort;
            string         Tim            = packetCompInfo.TimeVal;
            int            HeaderLength   = packetCompInfo.HeaderLength;
            int            TimeToLive     = packetCompInfo.TimeToLive;
            string         protocol       = packetCompInfo.Protocol;
            string         Flags          = packetCompInfo.Flags;
            string         epochTime      = packetCompInfo.EpochTime;

            ((TreeViewItem)treeviewPacket.Items[0]).Header = "Frame " + (No + ": " + framelentgh + " bytes on wire (" + (framelentgh * 8).ToString() +
                                                                         " bits), " + framelentgh + " bytes captured (" + (framelentgh * 8).ToString() + " bits) on interface " + Globals.Index.ToString());;
            ((TreeViewItem)treeviewPacket.Items[1]).Header = "Ethernet II, Src:" + (sourceMac + ", Dst: " + destMac);
            ((TreeViewItem)treeviewPacket.Items[2]).Header = "Internet Protocol Version" + (type[(type.Length - 1)].ToString() + ", Src: " + source + ", Dst: " + dest);
            if (protocol == "UDP")
            {
                ((TreeViewItem)treeviewPacket.Items[3]).Header = ("User Datagram Protocol, Src Port: " + sourcePort + ", Dst Port: " + destPort);
            }
            else if (protocol == "IGMP")
            {
                ((TreeViewItem)treeviewPacket.Items[3]).Header = "Internet Group Management Protocol";
            }
            else if (protocol == "ICMPV6")
            {
                ((TreeViewItem)treeviewPacket.Items[3]).Header = "Internet Control Message Protocol v6";
            }
            else
            {
                ((TreeViewItem)treeviewPacket.Items[3]).Header = "Transmission Control Protocol, Src Port:" + (sourcePort + ", Dst Port: " + destPort);
            }
            //add data to nades of root 0 (frame)
            ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[0]).Items[0])).Header = "Interface id: " + (Globals.Index.ToString() + " " + Globals.Device.Name.ToString());
            ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[0]).Items[2])).Header = "Arrival Time: " + Tim;
            ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[0]).Items[3])).Header = "Epoch Time: " + epochTime;
            ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[0]).Items[4])).Header = "Frame Number: " + frameNum;
            ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[0]).Items[5])).Header = "Frame Length: " + framelentgh + " bytes";
            ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[0]).Items[6])).Header = "Capture Length: " + capturelength + " bytes";
            //add data to nades of root 1 (ethernet)
            ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[1]).Items[0])).Header = "Source: " + sourceMac;
            ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[1]).Items[1])).Header = "Destination: " + destMac;
            ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[1]).Items[2])).Header = "Type: " + type;
            //add data to nades of root 2 (IP)
            ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[2]).Items[0])).Header = "Version: " + (type[(type.Length - 1)].ToString());
            ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[2]).Items[1])).Header = "Header Length: " + HeaderLength;
            ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[2]).Items[2])).Header = "Time to live: " + TimeToLive;
            ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[2]).Items[3])).Header = "Protocol: " + protocol;
            ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[2]).Items[4])).Header = "Source: " + source;
            ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[2]).Items[5])).Header = "Destination: " + dest;
            //add data to nades of root 3 (Transmission)
            if (protocol == "IGMP")
            {
                ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[3]).Items[0])).Header = "Type: " + sourcePort;
                ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[3]).Items[1])).Header = "Max Resp Time: " + destPort;
                ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[3]).Items[2])).Header = "Multicast Address: " + Flags;
            }
            else if (protocol == "ICMPV6")
            {
                ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[3]).Items[0])).Header = "Type: " + sourcePort;
                ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[3]).Items[1])).Header = "Code: 0" + destPort;
                ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[3]).Items[2])).Header = "Flags: " + Flags;
            }
            else
            {
                ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[3]).Items[0])).Header = "Source Port: " + sourcePort;
                ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[3]).Items[1])).Header = "Destination Port: " + destPort;
                ((TreeViewItem)(((TreeViewItem)treeviewPacket.Items[3]).Items[2])).Header = "Flags: " + Flags;
            }
        }
Пример #4
0
        private void refreshData(int capnum, int fraLen, DateTime dateTime, double seconds, string timeVal, string epochTime
                                 , string linkType, string sMac, string dMac, int linkHeadLen, string ethType, string sIp, string dIp, int TTL, int IpTotalLen
                                 , int ipHeadLen, int ipChecksum, int version, string ipType, int sPort, int dPort, long seqNum, long ackNum
                                 , int tranTotalLen, int tranHeadLen, int windowSize, int tranChecksum, int dataLen, string info, string flag, bool compMAC, bool compIP)
        {
            //1插入简单
            PacketSimpInfo packetSimpInfo = new PacketSimpInfo(capnum, timeVal, sIp, dIp, ipType, fraLen, info);

            ThreadPool.QueueUserWorkItem(delegate
            {
                this.Dispatcher.Invoke(new Action(() =>
                {
                    packetSimpInfos.Add(packetSimpInfo);
                }), null);
            });


            //2.插入复杂
            PacketCompInfo packetCompInfo = new PacketCompInfo(capnum, capnum, fraLen, fraLen, epochTime, sMac, dMac, ethType, sIp, dIp, sPort, dPort, timeVal, ipHeadLen, TTL, ipType, flag);

            packetCompInfos.Add(packetCompInfo);

            //3。插入完整
            PacketInfo packetInfo = new PacketInfo(capnum, fraLen, dateTime, seconds, timeVal, epochTime, linkType, sMac, dMac, ethType
                                                   , sIp, dIp, TTL, IpTotalLen, ipHeadLen, ipChecksum, version, ipType, sPort, dPort, seqNum
                                                   , ackNum, tranHeadLen, windowSize, tranChecksum, dataLen, info, flag);

            packetInfos.Add(packetInfo);
            //4.插入实时 (更改datetime)
            RealTimeInfo realTimeInfo = new RealTimeInfo(capnum, new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second), seconds, ethType, fraLen, ipType);

            //5.插入实时本地
            //System.Object lockthis = (System.Object)seconds;
            //lock (lockthis)
            //{
            if (!IOChartStatisticsWindow.RealTimeInfos.ContainsKey((int)seconds))
            {
                RealChartItem realChartItem = new RealChartItem((int)seconds, dateTime, 1, fraLen);
                IOChartStatisticsWindow.RealTimeInfos.Add((int)seconds, realChartItem);
            }
            else
            {
                IOChartStatisticsWindow.RealTimeInfos[(int)seconds].Count++;
                IOChartStatisticsWindow.RealTimeInfos[(int)seconds].SumLen += fraLen;
            }
            //}

            //统计1插入
            StatisticsInfo statisticsInfo = null;

            if (compIP == true)
            {//换
                if (compMAC == true)
                {
                    statisticsInfo = new StatisticsInfo(fraLen, seconds, linkType, dMac, sMac, linkHeadLen, ethType, dIp, sIp, IpTotalLen, ipHeadLen, ipType, dPort, sPort, tranTotalLen, tranHeadLen, dataLen, compMAC, compIP);
                }
                else
                {
                    statisticsInfo = new StatisticsInfo(fraLen, seconds, linkType, sMac, dMac, linkHeadLen, ethType, dIp, sIp, IpTotalLen, ipHeadLen, ipType, dPort, sPort, tranTotalLen, tranHeadLen, dataLen, compMAC, compIP);
                }
            }
            else
            {
                if (compMAC == true)
                {
                    statisticsInfo = new StatisticsInfo(fraLen, seconds, linkType, dMac, sMac, linkHeadLen, ethType, sIp, dIp, IpTotalLen, ipHeadLen, ipType, sPort, dPort, tranTotalLen, tranHeadLen, dataLen, compMAC, compIP);
                }
                else
                {
                    statisticsInfo = new StatisticsInfo(fraLen, seconds, linkType, sMac, dMac, linkHeadLen, ethType, sIp, dIp, IpTotalLen, ipHeadLen, ipType, sPort, dPort, tranTotalLen, tranHeadLen, dataLen, compMAC, compIP);
                }
            }

            //5 更新数据库
            //serviceStackDBHelper.InsertAllTable(packetSimpInfo, packetCompInfo, packetInfo, realTimeInfo);
            new Thread(() =>
            {
                serviceStackDBHelper.InsertSimpPcap(packetSimpInfo);
                serviceStackDBHelper.InsertCompPcap(packetCompInfo);
                serviceStackDBHelper.InsertPcap(packetInfo);
                serviceStackDBHelper.InsertRT(realTimeInfo);
                serviceStackDBHelper.InsertStatistics(statisticsInfo);
            }).Start();
        }