2009-01-29 115 views

回答

3

感謝所有,

我做了本規範再次

using System; 
    using System.Collections.Generic; 
    using System.Text; 
    using System.Net; 
    using System.Net.Sockets; 
    using System.DirectoryServices.AccountManagement; 
    using System.DirectoryServices.ActiveDirectory; 
public doIt() 
     { 
      DirectoryContext mycontext = new DirectoryContext(DirectoryContextType.Domain,"project.local"); 
      DomainController dc = DomainController.FindOne(mycontext); 
      IPAddress DCIPAdress = IPAddress.Parse(dc.IPAddress); 
     } 

感謝

+0

要檢索跨不同的域,你需要做:`new DirectoryContext(DirectoryContextType.Domain,「project.local」,「validUserInDomain」,「validUserPassword」); – 2012-11-13 14:45:54

1

那麼這裏是如何爲在MS網站描述得到它的一般工作流程:

http://support.microsoft.com/kb/247811

這裏是PInvoke.net鏈接調用引用DsGetDcName將功能:

http://pinvoke.net/default.aspx/netapi32/DsGetDcName.html

你可以下去,髒,如在第一個鏈接描述做原料DNS A記錄的查詢,但我認爲卡爾的PInvoke我應該做的伎倆。

希望幫助,

邁克

+0

還沒有在C#中嘗試過,但在Java中它是真實的容易去的DNS記錄路由。 – 2009-01-29 17:33:43

5

這是我會怎麼做。

您需要使用System.Net和System.DirectoryServices。

// get root of the directory data tree on a directory server 
DirectoryEntry dirEntry = new DirectoryEntry("LDAP://rootDSE"); 
// get the hostname of the directory server of your root (I'm assuming that's what you want) 
string dnsHostname = dirEntry.Properties["dnsHostname"].Value.ToString(); 
IPAddress[] ipAddresses = Dns.GetHostAddresses(dnsHostname);