Library

DNSJAVA
DNSPython

Dnsjava example

1
2
3
4
5
<dependency>
<groupId>dnsjava</groupId>
<artifactId>dnsjava</artifactId>
<version>2.1.6</version>
</dependency>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@Test
public void add() throws Exception{
private String dnsServer = "192.168.30.132";
Name zone = Name.fromString("abc.com.tw.");
Name host = Name.fromString("aaa", zone);
log.info("" + host);
Update update = new Update(zone);
update.add(host, Type.CNAME, DClass.IN, 400, "sdp", Name.fromString("cs."));
log.info("update: " + update);
Resolver res = new SimpleResolver(dnsServer);
res.setTSIGKey(new TSIG("example.com.","Roa6+m+40vuEHNJbMVTRjg=="));
res.setTCP(true);
Message response = res.send(update);
log.info("message: " + response.toString());
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@Test
public void delete() throws Exception{
private String dnsServer = "192.168.30.132";
Name zone = Name.fromString("abc.com.tw.");
Name host = Name.fromString("aaa", zone);
log.info("" + host);
Update update = new Update(zone);
update.delete(host, Type.CNAME, DClass.IN, 400, "sdp", Name.fromString("cs."));
log.info("update: " + update);
Resolver res = new SimpleResolver(dnsServer);
res.setTSIGKey(new TSIG("example.com.","Roa6+m+40vuEHNJbMVTRjg=="));
res.setTCP(true);
Message response = res.send(update);
log.info("message: " + response.toString());
}
1
2
3
4
5
6
7
8
9
10
11
12
13
@Test
public void get() throws Exception {
private String dnsServer = "192.168.30.132";
Name zone = Name.fromString("abc.com.tw.");
Name host = Name.fromString("aaa", zone);
Lookup l = new Lookup(host, Type.CNAME, DClass.IN);
l.setResolver(new SimpleResolver(dnsServer));
Record [] records = l.run();
for (int i = 0; i < records.length; i++) {
CNAMERecord r = (CNAMERecord) records[i];
log.info("record: " + r);
}
}