0

我需要使用 pcap4j 查找域中的所有邮件服务器

我用代码创建 MX DNS 数据包并发送它,但数据包要重新传输(wireshark img)

nslookup -type=mx vk.com 运行正常(cmd)

创建 Dns 数据包:

Random rnd=new Random();
DnsDomainName.Builder dnsName = new DnsDomainName.Builder();
dnsName.labels(Collections.singletonList("vk.com"));

DnsQuestion.Builder question = new DnsQuestion.Builder();
question.qName(dnsName.build()).qType(DnsResourceRecordType.MX).qClass(DnsClass.IN);

DnsPacket.Builder dns = new DnsPacket.Builder();
dns.response(false).
        id((short) rnd.nextInt()).
        opCode(DnsOpCode.QUERY).
        truncated(false).
        recursionDesired(true).
        authenticData(false).
        checkingDisabled(false).
        rCode(DnsRCode.NO_ERROR).
        qdCount((short)1).
        anCount((short)0).
        nsCount((short)0).
        arCount((short)0).
        questions(Collections.singletonList(question.build()));

UdpPacket.Builder udp = new UdpPacket.Builder();
udp.srcPort(new UdpPort((short) 53240, "start")).
        dstPort(new UdpPort((short) 53, "end")).
        length((short) 32).
        checksum((short) rnd.nextInt()).
        payloadBuilder(dns);

IpV4Packet.Builder ipv4 = new IpV4Packet.Builder();
ipv4.version(IpVersion.IPV4).
        ihl((byte) 5).
        tos(IpV4Rfc1349Tos.newInstance((byte) 0)).
        reservedFlag(false).
        moreFragmentFlag(false).
        dontFragmentFlag(false).
        fragmentOffset((short) 0).
        ttl((byte) 128).
        protocol(IpNumber.UDP).
        totalLength((short)52).
        payloadBuilder(udp).
        srcAddr((Inet4Address) InetAddress.getByName("192.168.43.72")).
        dstAddr((Inet4Address) InetAddress.getByName("192.168.43.1"));

EthernetPacket.Builder ether = new EthernetPacket.Builder();
ether.dstAddr(MacAddress.getByName("74:0a:e1:38:df:c7")).
        srcAddr(MacAddress.getByName("c4:6e:1f:11:53:10")).
        type(EtherType.IPV4).
        payloadBuilder(ipv4).
        paddingAtBuild(true);
Packet p = ether.build();
handle.sendPacket(p);
4

0 回答 0