如何获得短“域名” 来自dns域名?

发布于 2024-07-29 13:31:37 字数 816 浏览 1 评论 0原文

如果我对这个主题的理解有一些缺陷,请原谅我,我只知道我对域和活动目录的了解,因为我从使用它们中学到了一些东西。

域名有两个不同的“版本”。 第一个是我所说的 DNS 域名,类似于 company.int (对于用户 [email protected]),第二个类似于 prefixname (对于用户前缀名\max) 并且它们都指的是同一件事。

我的问题是,给定“company.int”,如何将其转换为“prefixname”?

编辑:或者给定 System.DirectoryServices.ActiveDirectory.Domain 对象,如何获取前缀名称?

EDIT2:此外,“前缀名称”还有其他名称吗? 我从来不知道该怎么称呼它。

EDIT3:我试图获取的值与 Windows 登录屏幕上显示的“登录到”(其中列出了域和您的计算机)的值相同。

EDIT4:我发现我可以通过执行以下操作来获取值:

SecurityIdentifier sid = GetCurrentUserSID();
string prefixName = sid.Translate(typeof(NTAccount)).Value.Split('\\')[0];

有谁知道获取此名称的更好方法吗?

Forgive me if my understanding of this topic has some shortcomings, I only know what I know about domains and active directory because of what I've picked up from working with them.

There are two different "versions" of a domain name. The first is what I call the DNS domain name which would be like company.int (for the user [email protected]) and the second would be like prefixname (for the user prefixname\max) and they would both refer to the same thing.

My question is, given "company.int", how do I convert that to "prefixname"?

EDIT: Or given a System.DirectoryServices.ActiveDirectory.Domain object, how do I get the prefixname?

EDIT2: Also, is there a name for the "prefixname" other than that? I never know what to call it.

EDIT3: The value I'm trying to get is the same value that shows up on the windows login screen for "Log on to" (where it lists the domains and your computer).

EDIT4: I've figured out I can get the value by doing the following:

SecurityIdentifier sid = GetCurrentUserSID();
string prefixName = sid.Translate(typeof(NTAccount)).Value.Split('\\')[0];

Does anyone know of a better method to get this name?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

木有鱼丸 2024-08-05 13:31:37

我希望这应该可以做到:

    private string GetNetbiosDomainName(string dnsDomainName)
    {
        string netbiosDomainName = string.Empty;

        DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE");

        string configurationNamingContext = rootDSE.Properties["configurationNamingContext"][0].ToString();

        DirectoryEntry searchRoot = new DirectoryEntry("LDAP://cn=Partitions," + configurationNamingContext);

        DirectorySearcher searcher = new DirectorySearcher(searchRoot);
        searcher.SearchScope = SearchScope.OneLevel;
        searcher.PropertiesToLoad.Add("netbiosname");
        searcher.Filter = string.Format("(&(objectcategory=Crossref)(dnsRoot={0})(netBIOSName=*))", dnsDomainName);

        SearchResult result = searcher.FindOne();

        if (result != null)
        {
            netbiosDomainName = result.Properties["netbiosname"][0].ToString();
        }

        return netbiosDomainName;
    }

您基本上用“mydomain.com”来调用它,并且应该返回netbios域名,例如“MYDOMAIN”(通常)。

马克

This should do it, I hope:

    private string GetNetbiosDomainName(string dnsDomainName)
    {
        string netbiosDomainName = string.Empty;

        DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE");

        string configurationNamingContext = rootDSE.Properties["configurationNamingContext"][0].ToString();

        DirectoryEntry searchRoot = new DirectoryEntry("LDAP://cn=Partitions," + configurationNamingContext);

        DirectorySearcher searcher = new DirectorySearcher(searchRoot);
        searcher.SearchScope = SearchScope.OneLevel;
        searcher.PropertiesToLoad.Add("netbiosname");
        searcher.Filter = string.Format("(&(objectcategory=Crossref)(dnsRoot={0})(netBIOSName=*))", dnsDomainName);

        SearchResult result = searcher.FindOne();

        if (result != null)
        {
            netbiosDomainName = result.Properties["netbiosname"][0].ToString();
        }

        return netbiosDomainName;
    }

You basically call it with the "mydomain.com" and should get back the netbios domain name, e.g. "MYDOMAIN" (usually).

Marc

梅窗月明清似水 2024-08-05 13:31:37

据我所知,prefixname始终是company.int的第一个标签(即company)。

To my knowledge, prefixname is always the first label of company.int (i.e. company).

白首有我共你 2024-08-05 13:31:37

您是否在寻找 System.DirectoryServices.DirectoryEntry.Path< /a>?

前缀名称只是称为域

编辑:
环境.UserDomainName 怎么样?

are you looking for System.DirectoryServices.DirectoryEntry.Path?

and the prefixname is just called domain

EDIT:
what about Environment.UserDomainName?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文