예제 #1
0
        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));
        }
예제 #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            object data = new DnsResourceDataDomainName(new DnsDomainName(txtData.Text));

            if (cmbDataType.SelectedIndex == 1)
            {
                data = new DnsResourceDataIpV4(new IpV4Address(txtData.Text));
            }
            else if (cmbDataType.SelectedIndex == 2)
            {
                data = new DnsResourceDataIpV6(new IpV6Address(txtData.Text));
            }
            DnsDataResourceRecord record = new DnsDataResourceRecord(
                new DnsDomainName(txtDomainName.Text),
                (DnsType)Enum.Parse(typeof(DnsType), cmbType.SelectedItem.ToString()),
                (DnsClass)Enum.Parse(typeof(DnsClass), cmbClass.SelectedItem.ToString())
                , int.Parse(txtTTL.Text),
                (DnsResourceData)data);

            tabDNS.addToAnswers(record);

            this.Close();
        }
예제 #3
0
파일: DnsTests.cs 프로젝트: preyea/Pcap.Net
 public void DnsResourceDataIpV4ParseWrongLengthTest()
 {
     var resourceData = new DnsResourceDataIpV4(IpV4Address.Zero);
     TestResourceRecordIsNotCreatedWithNewLength(DnsType.A, resourceData, 1);
 }
예제 #4
0
        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);
        }