This discussion is archived
0 Replies Latest reply: Mar 20, 2012 11:03 PM by 925295 RSS

Cname Help!

925295 Newbie
Currently Being Moderated
What java code to use for cname command :

I need to do this add CNAME to a DNS Host Server.

From the shell command :
m.<domain name> CNAME dns://....com

I have this code :

import javax.naming.*;
import javax.naming.directory.*;
import java.util.*;
import java.rmi.Remote;


public class DNSConnection     {
     public static void main(String[] args)     {
          try {
               Hashtable env = new Hashtable();
               env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
               env.put("java.naming.provider.url", "dns://....com");

               DirContext ctx = new InitialDirContext(env);

               
               Attributes attrs = ctx.getAttributes("somedomains.com", new String[] {"CNAME"});

               for (NamingEnumeration ae = attrs.getAll();ae.hasMoreElements();) {
                    Attribute attr = (Attribute)ae.next();
                    String attrId = attr.getID();
                    for (Enumeration vals = attr.getAll();vals.hasMoreElements(); System.out.println(attrId + ": " + vals.nextElement()));
               }

               ctx.close();
          }     
          catch(Exception e) {
               System.err.println("Problem querying DNS: " + e);
               e.printStackTrace();
          }
     }
}


Unfortunately, I can't really find any good answers on the net and I'm just starting. The code I posted is for getting all the data from the DNS server.

Help?


Thanks!

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points