2

プログラムでドメインコントローラーのIPアドレスを取得するにはどうすればよいですC#か?

4

3 に答える 3

6

Here's how I would do it.

You'll need to use System.Net and 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);
于 2009-01-29T17:54:34.767 に答える
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);
        }

再度、感謝します

于 2009-02-07T12:47:42.647 に答える
1

MS サイトで説明されているように、それを取得する方法の一般的なワークフローは次のとおりです。

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

参照されているDsGetDcName関数を呼び出すための PInvoke.net からのリンクを次に示します。

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

最初のリンクで説明されているように、ダウンして汚れて生の DNS A レコード クエリを実行することもできますが、PInvoke 呼び出しでうまくいくと思います。

それが役立つことを願って、

マイク

于 2009-01-29T17:00:53.190 に答える