public class DNS:System.IDisposable
     {
         string server=".";
         string userName=null;
         string Password=null;
         WbemScripting.SWbemLocatorClass sc=null;
         WbemScripting.SWbemServices svs=null;
         WbemScripting.SWbemObject dnsSrv=null;
         bool isConneced = false;        public string Server
         {
             get
             {
                 return server;
             }
             set
             {
                 server = value;
             }
         }        public DNS()
         {
             //
             // TODO: 在此处添加构造函数逻辑
             //
         }        public DNS(string server)
         {
             this.server = server;
         }        public DNS(string server,string username,string pwd)
         {
             this.server = server;
             this.userName=username;
             this.Password=pwd;
         }        ~DNS()
         {
             sc = null;
             svs = null;
             dnsSrv=null;
         }        public bool Connect()
         {
             sc = new WbemScripting.SWbemLocatorClass();
             try
             {
                 svs = sc.ConnectServer(server,@"\root\MicrosoftDNS",userName,Password,"","",0,null);
                 dnsSrv = svs.Get("MicrosoftDNS_Server.Name='"+server+"'",0,null);
                 this.isConneced=true;
             }
             catch(Exception e)
             {
                 //System.Web.HttpContext.Current.Response.Write(e);
                 Console.WriteLine(e);
                 this.isConneced=false;
             }
             return this.isConneced;
         }        public Exception AddARecord(string Domain,string HostName,string IPAddress)
         {
             if(!this.isConneced)
                 return new Exception("Not Connected!");            try
             {
                 object strRR = HostName+"."+Domain + ". IN A " + IPAddress;
                 object srv = server as Object;
                 object dm = Domain as Object;
                 //System.Web.HttpContext.Current.Response.Write(strRR+"<br>");
                 WbemScripting.SWbemObject objRR = svs.Get("MicrosoftDNS_ResourceRecord",0,null);                WbemScripting.SWbemMethod method = objRR.Methods_.Item("CreateInstanceFromTextRepresentation",0);
                 WbemScripting.SWbemObject inparam = method.InParameters;
                 inparam.Properties_.Add("DnsServerName",WbemScripting.WbemCimtypeEnum.wbemCimtypeString,false,0);
                 inparam.Properties_.Add("ContainerName",WbemScripting.WbemCimtypeEnum.wbemCimtypeString,false,0);
                 inparam.Properties_.Add("TextRepresentation",WbemScripting.WbemCimtypeEnum.wbemCimtypeString,false,0);
                 inparam.Properties_.Item("DnsServerName",0).set_Value(ref srv);
                 inparam.Properties_.Item("ContainerName",0).set_Value(ref dm);
                 inparam.Properties_.Item("TextRepresentation",0).set_Value(ref strRR);                objRR.ExecMethod_("CreateInstanceFromTextRepresentation",inparam,0,null);
                 return null;
             }
             catch(Exception ex)
             {
                 Console.WriteLine(ex);
                 return ex;
             }
             finally
             {
                 
             }
         }        public void StartDNSService()
         {
             this.dnsSrv.ExecMethod_("StartService",null,0,null);
         }        public void StopDNSService()
         {
             this.dnsSrv.ExecMethod_("StopService",null,0,null);
         }        public void StartScavenging()
         {
             this.dnsSrv.ExecMethod_("StartScavenging",null,0,null);
         }
         #region IDisposable 成员        public void Dispose()
         {
             sc = null;
             svs = null;
             dnsSrv=null;
         }        #endregion
     }一个用Com管理DNS的简单类
原创
             ©著作权归作者所有:来自51CTO博客作者biyusr216的原创作品,请联系作者获取转载授权,否则将追究法律责任        
            下一篇:UDP聊天示例
 
            
        
                提问和评论都可以,用心的回复会被更多人看到
                评论
            
            
                    发布评论
                
            
            相关文章
        
        
- 
                    用Java GUI做一个简单的管理系统Java初学者非常适用的管理系统 java 管理系统 gui
- 
                    一个简单的完成端口类iocp_server_client.aspx源代码下载源码使用了高级的完成端口(IOCP)技术,该技术可以有效地服务于多客户端。本文提出了一些IOCP编程中出现的实际问题的解决方法,并提供了一个简 服务器 socket 工作 多线程 asynchronous
- 
                    一个简单的加密/解密类这里,你可以使用.NET Framework自带的Secutil.exe工具,但据我所了解,Secutil工具的输出都是数组格式(我在自 java 服务器 mysql PublicKey System
 
 
                    













 
                    

 
                 
                    