HappyMeal HappyMeal - 1 year ago 104
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.

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download