0 Replies Latest reply: Mar 21, 2012 1:03 AM by 925295 RSS

    Cname Help!

    925295
      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!