/* * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * A DNS UDP message tracer. * * It listens for DNS UDP requests, forward request to real DNS server, receives * response message and sends back to requester, at same time dump all messages * into capture file * * The capture file contains an DNS protocol exchange in the hexadecimal * dump format emitted by HexDumpEncoder: * * xxxx: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ................ * * Typically, the capture file data will be used by DNSServer for playback
*/ publicclass DNSTracer extendsThreadimplements Server { publicstaticfinalint DNS_DEFAULT_PORT = 53; publicstaticfinalint DNS_PACKET_SIZE = 512; static HexDumpEncoder encoder = new HexDumpEncoder();
public DNSTracer(String dnsHostname, int dnsPort) throws SocketException { this(System.out, dnsHostname, dnsPort);
}
public DNSTracer(PrintStream outStream, String dnsHostname, int dnsPort) throws SocketException {
inSocket = new DatagramSocket(0, InetAddress.getLoopbackAddress());
out = outStream;
dnsServerAddress = new InetSocketAddress(dnsHostname, dnsPort);
}
publicvoid run() {
isRunning = true;
System.out.println( "DNSTracer: listening on port " + inSocket.getLocalPort());
System.out.println("DNSTracer: will forward request to server "
+ dnsServerAddress);
try (DatagramSocket outSocket = new DatagramSocket()) { while (true) {
DatagramPacket reqPacket = new DatagramPacket(reqBuffer.array(),
reqBuffer.array().length);
inSocket.receive(reqPacket);
out.println("-> " + reqPacket.getSocketAddress());
out.println(); // dump dns request data
out.println(encoder.encodeBuffer(
Arrays.copyOf(reqPacket.getData(),
reqPacket.getLength())));
out.println();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.