GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — dnsjava/EXAMPLES.md at master · msgpo/dnsjava

Expand file tree

/

EXAMPLES.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
81 lines (62 loc) · 1.99 KB
/

EXAMPLES.md

Copy path

File metadata and controls

81 lines (62 loc) · 1.99 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

dnsjava Examples

All of these examples are code fragments. Code using these fragments should check exceptions when appropriate, and should:

import org.xbill.DNS.*;

Get the IP address associated with a name

InetAddress addr = Address.getByName("www.dnsjava.org");

Get the MX target and preference of a name

Record[] records = new Lookup("gmail.com", Type.MX).run();
for (int i = 0; i < records.length; i++) {
    MXRecord mx = (MXRecord) records[i];
    System.out.println("Host " + mx.getTarget() + " has preference " + mx.getPriority());
}

Query a remote name server for its version

Lookup l = new Lookup("version.bind.", Type.TXT, DClass.CH);
l.setResolver(new SimpleResolver(args[0]));
l.run();
if (l.getResult() == Lookup.SUCCESSFUL) {
    System.out.println(l.getAnswers()[0].rdataToString());
}

Transfer a zone from a server and print it

ZoneTransferIn xfr = ZoneTransferIn.newAXFR(Name.root, "192.5.5.241", null);
xfr.run();
for (Record r : xfr.getAXFR()) {
    System.out.println(r);
}

Use DNS dynamic update to set the address of a host to a value specified on the command line

Name zone = Name.fromString("dyn.test.example.");
Name host = Name.fromString("host", zone);
Update update = new Update(zone);
update.replace(host, Type.A, 3600, args[0]);

Resolver res = new SimpleResolver("10.0.0.1");
res.setTSIGKey(new TSIG(host, base64.fromString("1234")));
res.setTCP(true);

Message response = res.send(update);

Manipulate domain names

Name n = Name.fromString("www.dnsjava.org");
Name o = Name.fromString("dnsjava.org");
System.out.println(n.subdomain(o));            // True

System.out.println(n.compareTo(o));            // > 0

Name rel = n.relativize(o);                    // the relative name 'www'
Name n2 = Name.concatenate(rel, o);
System.out.println(n2.equals(n));              // True

// www
// dnsjava
// org
for (int i = 0; i < n.labels(); i++) {
    System.out.println(n.getLabelString(i));
}
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.