Exemplo n.º 1
0
        private TreeViewItem MakeIPTreeNode(IPHeader ipHeader)
        {
            TreeViewItem ipItem = new TreeViewItem();

            ipItem.Header = "IP";
            ipItem.Items.Add("Ver: " + ipHeader.Version);
            ipItem.Items.Add("Header Length: " + ipHeader.HeaderLength);
            ipItem.Items.Add("Differntiated Services: " + ipHeader.DifferentiatedServices);
            ipItem.Items.Add("Total Length: " + ipHeader.TotalLength);
            ipItem.Items.Add("Identification: " + ipHeader.Identification);
            ipItem.Items.Add("Flags: " + ipHeader.Flags);
            ipItem.Items.Add("Fragmentation Offset: " + ipHeader.FragmentationOffset);
            ipItem.Items.Add("Time to live: " + ipHeader.TTL);
            switch (ipHeader.ProtocolType)
            {
                case Protocol.TCP:
                    ipItem.Items.Add("Protocol: " + "TCP");
                    break;
                case Protocol.UDP:
                    ipItem.Items.Add("Protocol: " + "UDP");
                    break;
                case Protocol.Unknown:
                    ipItem.Items.Add("Protocol: " + "Unknown");
                    break;
            }
            ipItem.Items.Add("Checksum: " + ipHeader.Checksum);
            ipItem.Items.Add("Source: " + ipHeader.SourceAddress.ToString());
            ipItem.Items.Add("Destination: " + ipHeader.DestinationAddress.ToString());

            return ipItem;
        }
Exemplo n.º 2
0
        private void ParseData(byte[] byteData, int nReceived)
        {
            this.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => {
                /*TreeViewItem rootNode = new TreeViewItem();

                //Since all protocol packets are encapsulated in the IP datagram
                //so we start by parsing the IP header and see what protocol data
                //is being carried by it
                IPHeader ipHeader = new IPHeader();
                ipHeader.Init(byteData, nReceived);

                TreeViewItem ipItem = MakeIPTreeNode(ipHeader);
                rootNode.Items.Add(ipItem);
                rootNode.Header = ipHeader.SourceAddress.ToString() + "-" +
                    ipHeader.DestinationAddress.ToString();

                treeView.Items.Add(rootNode);*/

                IPHeader ipHeader = new IPHeader();
                ipHeader.Init(byteData, nReceived);

                if (ipHeader.DestinationAddress.ToString().Equals(combInterfaces.Text)) return;

                bool isItemChanged = false;
                foreach (var el in listIPItems)
                {
                    if (el.IP.Equals(ipHeader.DestinationAddress.ToString()))
                    {
                        el.Count++;
                        listView.ItemsSource = null;
                        listView.ItemsSource = listIPItems;
                        isItemChanged = true;
                        break;
                    }
                }
                if (!isItemChanged)
                {
                    listIPItems.Add(new IPItem(ipHeader.DestinationAddress.ToString(), 1));
                }

            }));
        }