HappyMeal HappyMeal - 21 days ago 5x
Java Question

Finding all aliases for a server via Java code

I have faced with inability to find all aliases for a domain name using InetAddress. Is there any way to grep them through Java in order to accomplish matching the results getting after the execution of

nslookup domain_name
via cmd.


It seems the only way to do this is to use native command line lookup though java Runtime class and further parse the cmd result string as in the below example

 private static String execCmd(String cmd) {
    java.util.Scanner s = s = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\A");
    return s.hasNext() ? s.next() : StringUtils.EMPTY;