-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
75 lines (63 loc) · 2.62 KB
/
Test.java
File metadata and controls
75 lines (63 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.net.*;
import java.io.*;
import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.plaf.metal.*;
/**
* Creates a DNSPacket wiht a query, resolves that query, and
* displays the results
*
* @author Chris Blades
* @version 20/3/2010
*/
public class Test {
public static void main(String[] args) {
try {
DNSPacket packet = new DNSPacketImpl();
DNSFlagsField flags = new DNSFlagsFieldImpl();
flags.setIsRequest(false);
flags.setOpcode(DNSOpcodeEnum.QUERY);
DNSHeader header = new DNSHeaderImpl();
header.setIdentifier(456789);
header.setFlags(flags);
header.setNumQuestions(1);
DNSQuestion question = new DNSQuestionImpl();
question.setName(new DNSUrlImpl("www.yahoo.com"));
question.setType(DNSRecordTypeEnum.A);
question.setClass(DNSRecordClassEnum.IN);
packet.setHeader(header);
packet.setQuestion(question);
System.out.println(packet.stateValues().toString());
DatagramSocket sock = new DatagramSocket();
sock.send(new DatagramPacket(packet.serialize(),
packet.serialize().length,
InetAddress.getByName("8.8.4.4"),
53));
DatagramPacket get = new DatagramPacket(new byte[512], 512);
sock.receive(get);
byte[] packetbytes = get.getData();
Byte[] packetBytes = new Byte[packetbytes.length];
for (int i = 0; i < packetbytes.length; i++) {
packetBytes[i] = packetbytes[i];
}
DNSPacketParserDecorator dec =
new DNSPacketParserDecorator(
new IndexedArrayList<Byte>(packetBytes));
dec.parse();
DNSPacketGuiDecorator gui =
new DNSPacketGuiDecorator(dec);
UIManager.setLookAndFeel(new MetalLookAndFeel());
JFrame frame = new JFrame("DNS Resolver");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTree tree = new JTree(gui);
//frame.setSize(tree.getPreferredScrollableViewportSize());
frame.getContentPane().add(tree);
frame.setVisible(true);
} catch (Exception e) {
System.out.println("_______________________");
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}