Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7780461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:54:19+00:00 2026-06-01T18:54:19+00:00

In the below java code, I am making a DNS SRV record lookup to

  • 0

In the below java code, I am making a DNS SRV record lookup to resolve the target domain name and associated port for a given domain name such as root@1000000000.blubluzone.com. The lookup function indicated with /HERE/ below returns null somehow and I cannot get a a query result (i.e. record array is null). As a consequence, a null pointer exception is thrown when records array is accessed in the for loop.

What do you think I am missing to make the following code work. I am using using dnsjava and the related API jar file is available at http://www.dnsjava.org/download/ (at the bottom of the page). Thanks in advance for your suggestion.

     import org.xbill.DNS.Lookup;
     import org.xbill.DNS.Record;
     import org.xbill.DNS.SRVRecord;
     import org.xbill.DNS.TextParseException;
     import org.xbill.DNS.Type;

     public class DNSLookup {

        public static void main(String[] args) {

          if (args.length < 1) {
             System.err.println("Usage: java -jar DNSLookup <hostname>");
             System.exit(1);
          }

          String query = "_ssh._tcp." + args[0];

          try {
            /*****HERE*********/
            Record[] records = new Lookup(query, Type.SRV).run();

            for (Record record : records) {
                 SRVRecord srv = (SRVRecord) record;

            String hostname = srv.getTarget().toString().replaceFirst("\\.$", "");
            int port = srv.getPort();

            System.out.println(hostname + ":" + port);
          }
          } catch (TextParseException e) {
             e.printStackTrace();
          }
       }
      }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:54:21+00:00Added an answer on June 1, 2026 at 6:54 pm

    Your code is fine, except that Lookup.run() returns null (not an empty array) if no records are found.

    For example, if you replace _ssh._tcp with _nicname._tcp and then look up uk you’ll find an SRV record for the .UK whois server.

    If there’s a problem it’s with your input parameters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the Java code below, what's the closest you could represent these two static
I've got the following java code, which is giving the error below: import java.io.File;
Consider the Java code below, what would happen if there were no paintComponent method
IN JAVA CODE IN JSP as below i m getting null value for fieldnoOfRecords.
I need the java code snippet for the below logic: Following is a string
The below code in Java throws Null pointer exception. public class New{ int i;
I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {
I have a java file Test.java (below) which uses Guava's HashMultiMap (downloaded from http://code.google.com/p/guava-libraries/
I try use a integer array in java with the code below: public static
I have wrote the code below which was taken from Java How to program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.