Example #1
0
        public void packetarrive(object sender, CaptureEventArgs e)
        {
            packet p;

            try{
                p = new packet(e.Packet);
            }
            catch {
                return;
            }
            packets.Add(p);
            ProcessContext(p);
        }
Example #2
0
        public void ProcessContext(packet p)
        {
            if (p.Network_type == null || (p.Network_type != "IPV4" && p.Network_type != "IPV6" && p.Network_type != "ARP" && p.Network_type != "LLDP"))
            {
                ;
            }
            else if (Network_dic.ContainsKey(p.Network_type))
            {
                Network_dic[p.Network_type]++;
            }
            else
            {
                Network_dic[p.Network_type] = 1;
            }

            if (p.TRANS_type == null || p.TRANS_type == "139")
            {
                ;
            }
            else if (TRANS_dic.ContainsKey(p.TRANS_type))
            {
                TRANS_dic[p.TRANS_type]++;
            }
            else
            {
                TRANS_dic[p.TRANS_type] = 1;
            }

            p.index = (p.index == 0) ? (PacketsInfolistView.Items.Count + 1) : p.index;
            PacketsInfo psi = new PacketsInfo {
                ID         = p.index,
                ArriveTime = p.time,
                SourceAddr = p.source,
                SourcePort = p.srcPort,
                DestAddr   = p.destination,
                DestPort   = p.desPort,
                Protocol   = p.protocol,
                Length     = p.paclen,
                Color      = p.color
            };

            this.Dispatcher.Invoke(
                DispatcherPriority.Normal, (ThreadStart) delegate(){
                PacketsInfolistView.Items.Add(psi);
            }
                );
        }
Example #3
0
        private void OpenFile_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog openfile = new OpenFileDialog();
            openfile.InitialDirectory = Environment.CurrentDirectory;
            openfile.Filter           = "pcap files (*.pcap)|*.pcap";
            openfile.CheckFileExists  = true;
            openfile.RestoreDirectory = true;

            if (openfile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string name = openfile.FileName;

                PacketsInfolistView.Items.Clear();
                Network_dic = new Dictionary <string, int>();
                TRANS_dic   = new Dictionary <string, int>();

                this.packets = new ArrayList();

                SharpPcap.LibPcap.CaptureFileReaderDevice reader = new SharpPcap.LibPcap.CaptureFileReaderDevice(name);
                RawCapture rawp;

                try{
                    rawp = reader.GetNextPacket();
                    while (rawp != null)
                    {
                        packet temp = new packet(rawp);
                        packets.Add(temp);

                        ProcessContext(temp);

                        rawp = reader.GetNextPacket();
                    }
                    MessageBox.Show("success!");
                }
                catch (Exception) {
                    MessageBox.Show("fail!");
                }
            }
        }
Example #4
0
        private void PacketsInfoList_MouseDoubleClick(object sender, RoutedEventArgs e)
        {
            var         listview    = sender as ListView;
            var         currentitem = listview.SelectedItem;
            PacketsInfo psi         = (PacketsInfo)currentitem;
            packet      pac         = (packet)packets[psi.ID - 1];

            PackettreeView.Items.Clear();

            if (pac.PacketInforArray.Count > 0)
            {
                TreeViewItem item1 = new TreeViewItem();
                item1.Header = "Frame:";
                for (int i = 0; i < pac.PacketInforArray.Count; i++)
                {
                    item1.Items.Add(pac.PacketInforArray[i].ToString().Replace("\n", ""));
                }
                PackettreeView.Items.Add(item1);

                // PackettreeView.Items.Add("Frame: ");
                // DockPanel dp= new DockPanel();
                // for(int i = 0; i < pac.PacketInforArray.Count; i++){
                //     TextBlock tb = new TextBlock();
                //     tb.Text = pac.PacketInforArray[i].ToString();
                //     dp.Children.Add(tb);
                // }
                // (PackettreeView.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem).Items.Add(dp);
            }

            if (pac.EthernetInforArray.Count > 0)
            {
                TreeViewItem item2 = new TreeViewItem();
                item2.Header = "Ethernet:";
                for (int i = 0; i < pac.EthernetInforArray.Count; i++)
                {
                    item2.Items.Add(pac.EthernetInforArray[i].ToString().Replace("\n", ""));
                }
                PackettreeView.Items.Add(item2);
            }

            if (pac.IpInforArray.Count > 0)
            {
                TreeViewItem item3 = new TreeViewItem();
                item3.Header = "Internet Protocol:";
                for (int i = 0; i < pac.IpInforArray.Count; i++)
                {
                    item3.Items.Add(pac.IpInforArray[i].ToString().Replace("\n", ""));
                }
                PackettreeView.Items.Add(item3);
            }

            if (pac.IcmpInforArray.Count > 0)
            {
                TreeViewItem item4 = new TreeViewItem();
                item4.Header = "Internet Control Message Protocol:";
                for (int i = 0; i < pac.IcmpInforArray.Count; i++)
                {
                    item4.Items.Add(pac.IcmpInforArray[i].ToString().Replace("\n", ""));
                }
                PackettreeView.Items.Add(item4);
            }

            if (pac.UdpInforArray.Count > 0)
            {
                TreeViewItem item5 = new TreeViewItem();
                item5.Header = "Internet Control Message Protocol:";
                for (int i = 0; i < pac.UdpInforArray.Count; i++)
                {
                    item5.Items.Add(pac.UdpInforArray[i].ToString().Replace("\n", ""));
                }
                PackettreeView.Items.Add(item5);
            }

            if (pac.TcpInforArray.Count > 0)
            {
                TreeViewItem item6 = new TreeViewItem();
                item6.Header = "Transmission Control Protocol:";
                for (int i = 0; i < pac.TcpInforArray.Count; i++)
                {
                    item6.Items.Add(pac.TcpInforArray[i].ToString().Replace("\n", ""));
                }
                PackettreeView.Items.Add(item6);
            }

            if (pac.ArpInforArray.Count > 0)
            {
                TreeViewItem item7 = new TreeViewItem();
                item7.Header = "Address Resolution Protocol:";
                for (int i = 0; i < pac.ArpInforArray.Count; i++)
                {
                    item7.Items.Add(pac.ArpInforArray[i].ToString().Replace("\n", ""));
                }
                PackettreeView.Items.Add(item7);
            }

            if (pac.ApplicationInfor.Count > 0)
            {
                TreeViewItem item8 = new TreeViewItem();
                item8.Header = "Application Layer Protocol:";
                for (int i = 0; i < pac.ApplicationInfor.Count; i++)
                {
                    item8.Items.Add(pac.ApplicationInfor[i].ToString().Replace("\n", ""));
                }
                PackettreeView.Items.Add(item8);
            }

            PacketStatus.Text = str2hex(pac.rawp.Data);
        }