Example #1
0
 public simplePacket(packet p)
 {
     this.src    = p.ip4.SourceAddress.ToString();
     this.des    = p.ip4.DestinationAddress.ToString();
     this.id     = p.ip4.Id.ToString();
     this.length = p.ip4.TotalLength - p.ip4.HeaderLength * 4;
     this.offset = p.ip4.FragmentOffset;
     this.mf     = (p.ip4.Bytes[6] / 32) % 2;
     this.df     = (p.ip4.Bytes[6] / 64) % 2;
     this.data   = p.data;
 }
Example #2
0
        //
        //display the packets onto the listview.
        //
        public void ProcessContext(RawCapture pac)
        {
            packet p = new packet(pac);

            packets.Add(p);
            p.index = (listView1.Items.Count + 1);
            ListViewItem item = new ListViewItem(new string[] { p.index.ToString(), p.time, p.source, p.destination, p.protocol, p.information });

            item.BackColor = Color.FromName(p.color);
            listView1.Items.Add(item);
        }
Example #3
0
        //
        //open file
        //
        private void open_Click(object sender, EventArgs 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;

                listView1.Items.Clear();
                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);

                        temp.index = (listView1.Items.Count + 1);

                        ListViewItem item = new ListViewItem(new string[] { temp.index.ToString(), temp.time, temp.source, temp.destination, temp.protocol, temp.information });
                        item.BackColor = Color.FromName(temp.color);
                        listView1.Items.Add(item);


                        rawp = reader.GetNextPacket();
                    }
                    MessageBox.Show("success!");
                }
                catch (Exception)
                {
                    MessageBox.Show("fail!");
                }
            }
        }
Example #4
0
        //
        //to show the details of a packet in treeview
        //
        private void listView1_Click(object sender, EventArgs e)
        {
            int    index = Convert.ToInt32(this.listView1.SelectedItems[0].Text);
            packet pac   = (packet)packets[index - 1];

            this.treeView1.Nodes.Clear();

            label4.Text = "layer:" + pac.layer + "\nepac:" + pac.epac + "\nhash:" + pac.GetHashCode() + "\ninformation:" + pac.information + "\ntime:" + pac.time + "\ndata:" + pac.data;


            if (pac.PacketInforArray.Count > 0)
            {
                TreeNode new1 = new TreeNode("Frame: ");
                for (int i = 0; i < pac.PacketInforArray.Count; i++)
                {
                    new1.Nodes.Add(pac.PacketInforArray[i].ToString());
                }
                this.treeView1.Nodes.Add(new1);
            }

            if (pac.EthernetInforArray.Count > 0)
            {
                TreeNode new2 = new TreeNode("Ethernet:");
                for (int i = 0; i < pac.EthernetInforArray.Count; i++)
                {
                    new2.Nodes.Add(pac.EthernetInforArray[i].ToString());
                }
                this.treeView1.Nodes.Add(new2);
            }

            if (pac.IpInforArray.Count > 0)
            {
                TreeNode new3 = new TreeNode("Internet Protocol:");
                for (int i = 0; i < pac.IpInforArray.Count; i++)
                {
                    new3.Nodes.Add(pac.IpInforArray[i].ToString());
                }
                this.treeView1.Nodes.Add(new3);
            }

            if (pac.IcmpInforArray.Count > 0)
            {
                TreeNode new4 = new TreeNode("Internet Control Message Protocol: ");
                for (int i = 0; i < pac.IcmpInforArray.Count; i++)
                {
                    new4.Nodes.Add(pac.IcmpInforArray[i].ToString());
                }
                this.treeView1.Nodes.Add(new4);
            }

            if (pac.UdpInforArray.Count > 0)
            {
                TreeNode new5 = new TreeNode("User Datagram Protocol: ");
                for (int i = 0; i < pac.UdpInforArray.Count; i++)
                {
                    new5.Nodes.Add(pac.UdpInforArray[i].ToString());
                }
                this.treeView1.Nodes.Add(new5);
            }

            if (pac.TcpInforArray.Count > 0)
            {
                TreeNode new6 = new TreeNode("Transmission Control Protocol: ");
                for (int i = 0; i < pac.TcpInforArray.Count; i++)
                {
                    new6.Nodes.Add(pac.TcpInforArray[i].ToString());
                }
                this.treeView1.Nodes.Add(new6);
            }

            if (pac.ArpInforArray.Count > 0)
            {
                TreeNode new7 = new TreeNode("Address Resolution Protocol: ");
                for (int i = 0; i < pac.ArpInforArray.Count; i++)
                {
                    new7.Nodes.Add(pac.ArpInforArray[i].ToString());
                }
                this.treeView1.Nodes.Add(new7);
            }

            if (pac.ApplicationInfor.Count > 0)
            {
                TreeNode new8 = new TreeNode("Application Layer Protocol: ");
                for (int i = 0; i < pac.ApplicationInfor.Count; i++)
                {
                    new8.Nodes.Add(pac.ApplicationInfor[i].ToString());
                }
                this.treeView1.Nodes.Add(new8);
            }
        }