Beispiel #1
0
        private void DisplayPacketData(Packet packet)
        {
            packetsCount++;
            packetsDictionary.AddOrUpdate(packetsCount, packet, (i, p) => p);

            ListViewItem packetItem;

            if (packet is ARPPacket)
            {
                ARPPacket arpPacket = (ARPPacket)packet;

                packetItem = ListViewVisualizer.GenerateListViewItem(
                    Color.LightPink,
                    packetsCount.ToString(),
                    TreeViewVisualizer.GetHyphenatedHwAddress(arpPacket.ARPSenderHwAddress),
                    String.Empty,
                    String.Empty,
                    TreeViewVisualizer.GetHyphenatedHwAddress(arpPacket.ARPTargetHwAddress),
                    String.Empty,
                    String.Empty,
                    "ARP",
                    arpPacket.ToString());
            }
            else if (packet is ICMPPacket)
            {
                ICMPPacket icmpPacket = (ICMPPacket)packet;

                packetItem = ListViewVisualizer.GenerateListViewItem(
                    Color.Thistle,
                    packetsCount.ToString(),
                    icmpPacket.SourceAddress.ToString(),
                    DnsTable.GetHostByAddress(icmpPacket.SourceAddress),
                    String.Empty,
                    icmpPacket.DestinationAddress.ToString(),
                    DnsTable.GetHostByAddress(icmpPacket.DestinationAddress),
                    String.Empty,
                    "ICMP",
                    icmpPacket.ToString());
            }
            else if (packet is TCPPacket)
            {
                TCPPacket tcpPacket = (TCPPacket)packet;

                packetItem = ListViewVisualizer.GenerateListViewItem(
                    Color.LightSkyBlue,
                    packetsCount.ToString(),
                    tcpPacket.SourceAddress.ToString(),
                    DnsTable.GetHostByAddress(tcpPacket.SourceAddress),
                    tcpPacket.SourcePort.ToString(),
                    tcpPacket.DestinationAddress.ToString(),
                    DnsTable.GetHostByAddress(tcpPacket.DestinationAddress),
                    tcpPacket.DestinationPort.ToString(),
                    "TCP",
                    tcpPacket.ToString());
            }
            else if (packet is UDPPacket)
            {
                UDPPacket udpPacket = (UDPPacket)packet;

                packetItem = ListViewVisualizer.GenerateListViewItem(
                    Color.LemonChiffon,
                    packetsCount.ToString(),
                    udpPacket.SourceAddress.ToString(),
                    DnsTable.GetHostByAddress(udpPacket.SourceAddress),
                    udpPacket.SourcePort.ToString(),
                    udpPacket.DestinationAddress.ToString(),
                    DnsTable.GetHostByAddress(udpPacket.DestinationAddress),
                    udpPacket.DestinationPort.ToString(),
                    "UDP",
                    udpPacket.ToString());
            }
            else
            {
                packetItem = ListViewVisualizer.GenerateListViewItem(
                    Color.Linen,
                    packetsCount.ToString(),
                    String.Empty,
                    String.Empty,
                    String.Empty,
                    String.Empty,
                    String.Empty,
                    String.Empty,
                    "unknown",
                    String.Empty);
            }

            AddListViewItemDelegate addListViewItemDelegate = new AddListViewItemDelegate(ListViewVisualizer.AddListViewItem);

            listViewPackets.Invoke(addListViewItemDelegate, new object[] { packetItem, listViewPackets });

            ShowDisplayedPacketsCountDelegate showDisplayedPacketsDelegate = new ShowDisplayedPacketsCountDelegate(StatusStripVisualizer.SetLabelText);

            statusStrip.Invoke(showDisplayedPacketsDelegate, new object[] { toolStripStatusLabelPacketsInfo.Name, String.Format("|Displayed packets: {0}", packetsCount), statusStrip });

            if (packetsCount == 1)
            {
                UpdateTreeViewDelegate updateTreeViewDelegate = new UpdateTreeViewDelegate(TreeViewVisualizer.UpdateTreeView);
                treeViewPacketInfo.Invoke(updateTreeViewDelegate, new object[] { (Packet)packetsDictionary[1], treeViewPacketInfo });

                FillGridViewDelegate fillGridViewDelegate = new FillGridViewDelegate(DataGridViewVisualizer.FillDataGridView);
                dataGridViewPacketData.Invoke(fillGridViewDelegate, new object[] { (Packet)packetsDictionary[1], dataGridViewPacketData });
            }
        }
        private void DisplayPacketData(Packet packet)
        {
            packetsCount++;
            packetsDictionary.AddOrUpdate(packetsCount, packet, (i, p) => p);

            ListViewItem packetItem;

            if (packet is ARPPacket)
            {
                ARPPacket arpPacket = (ARPPacket)packet;

                packetItem = ListViewVisualizer.GenerateListViewItem(
                    Color.LightPink,
                    packetsCount.ToString(),
                    TreeViewVisualizer.GetHyphenatedHwAddress(arpPacket.ARPSenderHwAddress),
                    String.Empty,
                    String.Empty,
                    TreeViewVisualizer.GetHyphenatedHwAddress(arpPacket.ARPTargetHwAddress),
                    String.Empty,
                    String.Empty,
                    "ARP",
                    arpPacket.ToString());
            }
            else if (packet is ICMPPacket)
            {
                ICMPPacket icmpPacket = (ICMPPacket)packet;

                packetItem = ListViewVisualizer.GenerateListViewItem(
                    Color.Thistle,
                    packetsCount.ToString(),
                    icmpPacket.SourceAddress.ToString(),
                    DnsTable.GetHostByAddress(icmpPacket.SourceAddress),
                    String.Empty,
                    icmpPacket.DestinationAddress.ToString(),
                    DnsTable.GetHostByAddress(icmpPacket.DestinationAddress),
                    String.Empty,
                    "ICMP",
                    icmpPacket.ToString());
            }
            else if (packet is TCPPacket)
            {
                TCPPacket tcpPacket = (TCPPacket)packet;

                packetItem = ListViewVisualizer.GenerateListViewItem(
                    Color.LightSkyBlue,
                    packetsCount.ToString(),
                    tcpPacket.SourceAddress.ToString(),
                    DnsTable.GetHostByAddress(tcpPacket.SourceAddress),
                    tcpPacket.SourcePort.ToString(),
                    tcpPacket.DestinationAddress.ToString(),
                    DnsTable.GetHostByAddress(tcpPacket.DestinationAddress),
                    tcpPacket.DestinationPort.ToString(),
                    "TCP",
                    tcpPacket.ToString());
            }
            else if (packet is UDPPacket)
            {
                UDPPacket udpPacket = (UDPPacket)packet;

                packetItem = ListViewVisualizer.GenerateListViewItem(
                    Color.LemonChiffon,
                    packetsCount.ToString(),
                    udpPacket.SourceAddress.ToString(),
                    DnsTable.GetHostByAddress(udpPacket.SourceAddress),
                    udpPacket.SourcePort.ToString(),
                    udpPacket.DestinationAddress.ToString(),
                    DnsTable.GetHostByAddress(udpPacket.DestinationAddress),
                    udpPacket.DestinationPort.ToString(),
                    "UDP",
                    udpPacket.ToString());
            }
            else
            {
                packetItem = ListViewVisualizer.GenerateListViewItem(
                    Color.Linen,
                    packetsCount.ToString(),
                    String.Empty,
                    String.Empty,
                    String.Empty,
                    String.Empty,
                    String.Empty,
                    String.Empty,
                    "unknown",
                    String.Empty);
            }

            AddListViewItemDelegate addListViewItemDelegate = new AddListViewItemDelegate(ListViewVisualizer.AddListViewItem);
            listViewPackets.Invoke(addListViewItemDelegate, new object[] { packetItem, listViewPackets });

            ShowDisplayedPacketsCountDelegate showDisplayedPacketsDelegate = new ShowDisplayedPacketsCountDelegate(StatusStripVisualizer.SetLabelText);
            statusStrip.Invoke(showDisplayedPacketsDelegate, new object[] { toolStripStatusLabelPacketsInfo.Name, String.Format("|Displayed packets: {0}", packetsCount), statusStrip });

            if (packetsCount == 1)
            {
                UpdateTreeViewDelegate updateTreeViewDelegate = new UpdateTreeViewDelegate(TreeViewVisualizer.UpdateTreeView);
                treeViewPacketInfo.Invoke(updateTreeViewDelegate, new object[] { (Packet)packetsDictionary[1], treeViewPacketInfo });

                FillGridViewDelegate fillGridViewDelegate = new FillGridViewDelegate(DataGridViewVisualizer.FillDataGridView);
                dataGridViewPacketData.Invoke(fillGridViewDelegate, new object[] { (Packet)packetsDictionary[1], dataGridViewPacketData });
            }
        }