Exemplo n.º 1
0
        private void listPackets_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            string protocol = e.Item.SubItems[3].Text;
            int    key      = Int32.Parse(e.Item.SubItems[0].Text);
            Packet packet;
            bool   hasPacket = capturedPackets_list.TryGetValue(key, out packet);

            textProperties.Text = "";

            IIpHeader ipHeader;

            if (hasPacket)
            {
                MemoryStream memoryStream = new MemoryStream(packet.PayloadPacket.Header, 0, packet.PayloadPacket.Header.Length);
                BinaryReader binaryReader = new BinaryReader(memoryStream);

                if (((PacketDotNet.EthernetPacket)packet).Type == PacketDotNet.EthernetPacketType.IpV4)
                {
                    ipHeader = new IPHeaderV4(binaryReader);
                    MakeInformationIP(ipHeader);
                }
                else if (((PacketDotNet.EthernetPacket)packet).Type == PacketDotNet.EthernetPacketType.IpV6)
                {
                    ipHeader = new IPHeaderV6(binaryReader);
                    MakeInformationIP(ipHeader);
                }
                else
                {
                    textProperties.Text = "Desconhecido";
                }

                textProperties.Text += "\r\n";

                if (protocol.Equals("TCP"))
                {
                    var tcpPacket = (TcpPacket)packet.Extract(typeof(TcpPacket));
                    if (tcpPacket != null)
                    {
                        var tcpHeader = new TCPHeader(tcpPacket);
                        MakeInformationTCP(tcpHeader);
                    }
                }
                else if (protocol.Equals("UDP"))
                {
                    var udpPacket = (UdpPacket)packet.Extract(typeof(UdpPacket));
                    if (udpPacket != null)
                    {
                        var udpHeader = new UDPHeader(udpPacket);
                        MakeInformationUDP(udpHeader);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void listPackets_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            string protocol = e.Item.SubItems[3].Text;
            int    key      = Int32.Parse(e.Item.SubItems[0].Text);
            Packet packet;
            bool   hasPacket = capturedPackets_list.TryGetValue(key, out packet);

            IIpHeader ipHeader;

            if (hasPacket)
            {
                MemoryStream memoryStream = new MemoryStream(packet.PayloadPacket.Header, 0, packet.PayloadPacket.Header.Length);
                BinaryReader binaryReader = new BinaryReader(memoryStream);
                treeView1.Nodes.Clear();

                if (((PacketDotNet.EthernetPacket)packet).Type == PacketDotNet.EthernetPacketType.IpV4)
                {
                    ipHeader = new IPHeaderV4(binaryReader, this.ip2l);
                    MakeInformationIP(ipHeader);
                }
                else if (((PacketDotNet.EthernetPacket)packet).Type == PacketDotNet.EthernetPacketType.IpV6)
                {
                    ipHeader = new IPHeaderV6(binaryReader, this.ip2l);
                    MakeInformationIP(ipHeader);
                }
                else
                {
                    treeView1.Nodes.Add("Desconhecido");
                }

                if (protocol.Equals("TCP"))
                {
                    var tcpPacket = (TcpPacket)packet.Extract(typeof(TcpPacket));
                    if (tcpPacket != null)
                    {
                        var tcpHeader = new TCPHeader(tcpPacket);
                        MakeInformationTCP(tcpHeader);
                    }
                }
                else if (protocol.Equals("UDP"))
                {
                    var udpPacket = (UdpPacket)packet.Extract(typeof(UdpPacket));
                    if (udpPacket != null)
                    {
                        var udpHeader = new UDPHeader(udpPacket);
                        MakeInformationUDP(udpHeader);
                    }
                }
                else if (protocol.Equals("ICMP"))
                {
                    var icmpv4Packet = (ICMPv4Packet)packet.Extract(typeof(ICMPv4Packet));
                    if (icmpv4Packet != null)
                    {
                        var icmpv4Header = new ICMPv4Header(icmpv4Packet);
                        MakeInformationICMPv4(icmpv4Header);
                    }
                }
                else if (protocol.Equals("ICMPV6"))
                {
                    var icmpv6Packet = (ICMPv6Packet)packet.Extract(typeof(ICMPv6Packet));
                    if (icmpv6Packet != null)
                    {
                        var icmpv6Header = new ICMPv6Header(icmpv6Packet);
                        MakeInformationICMPv6(icmpv6Header);
                    }
                }

                treeView1.ExpandAll();
            }
        }