コード例 #1
0
        public static TreeViewItem EthernetTreeViewItem(EthernetDatagram ethernetDatagram)
        {
            var treeViewItem = new TreeViewItem
            {

                DataContext = ethernetDatagram,
                HeaderTemplate = (Helpers.GetResourceItem()["EtherItem"] as DataTemplate)
            };

            treeViewItem.Items.Add(new TreeViewItem { Header = string.Format("Source : {0}", ethernetDatagram.Source) });
            treeViewItem.Items.Add(new TreeViewItem { Header = string.Format("Destination : {0}", ethernetDatagram.Destination) });
            treeViewItem.Items.Add(new TreeViewItem { Header = string.Format("Header Length : {0} byte(s)", ethernetDatagram.HeaderLength) });
            treeViewItem.Items.Add(new TreeViewItem { Header = string.Format("Payload Length : {0} byte(s)", ethernetDatagram.PayloadLength) });
            var payload = new TreeViewItem
            {
                Header = string.Format("Payload : {0}", "0x" + ethernetDatagram.Payload.ToHexadecimalString())
            };

            payload.MouseDoubleClick += delegate
            {
                Clipboard.SetText(ethernetDatagram.Payload.ToHexadecimalString());
            };
            treeViewItem.Items.Add(payload);

            return treeViewItem;
        }
コード例 #2
0
        public override void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer)
        {
            EthernetType       ethernetType      = EthernetBaseLayer.GetEthernetType(this.EtherType, nextLayer);
            MacAddress         destination       = this.Destination;
            IEthernetNextLayer ethernetNextLayer = nextLayer as IEthernetNextLayer;

            if (destination == MacAddress.Zero && ethernetNextLayer != null && ethernetNextLayer.PreviousLayerDefaultDestination.HasValue)
            {
                destination = ethernetNextLayer.PreviousLayerDefaultDestination.Value;
            }
            EthernetDatagram.WriteHeader(buffer, offset, this.Source, destination, ethernetType);
        }
コード例 #3
0
ファイル: ArpPoisoner.cs プロジェクト: bmuthoga/dipw
        public Packet CreateDnsReply(EthernetDatagram etherpacket, IpV4Address newAddress)
        {
            var ipPacket = etherpacket.IpV4;
            var udpPacket = ipPacket.Udp;
            var dnsPacket = udpPacket.Dns;

            if (!dnsPacket.IsQuery)
                throw new Exception("Packet should be a dns query!");

            EthernetLayer ethernetLayer = new EthernetLayer
            {
                Source = etherpacket.Destination,
                Destination = etherpacket.Source,
            };

            IpV4Layer ipLayer = new IpV4Layer
            {
                Source = ipPacket.Destination,
                CurrentDestination = ipPacket.Source,
            };

            UdpLayer udpLayer = new UdpLayer
            {
                SourcePort = udpPacket.DestinationPort,
                DestinationPort = udpPacket.SourcePort
            };

            DnsResourceData resourceData = new DnsResourceDataIpV4(newAddress);
            DnsDataResourceRecord resourceRecord = new DnsDataResourceRecord(dnsPacket.Queries[0].DomainName,
                    dnsPacket.Queries[0].DnsType,
                    dnsPacket.Queries[0].DnsClass,
                    60,
                    resourceData);

            DnsLayer dnsLayer = new DnsLayer
            {
                Queries = dnsPacket.Queries,
                IsQuery = false,
                IsResponse = true,
                Id = dnsPacket.Id,
                Answers = new[] { resourceRecord }
            };

            PacketBuilder builder = new PacketBuilder(ethernetLayer, ipLayer, udpLayer, dnsLayer);
            return builder.Build(DateTime.Now);
        }