windows 如何从dns域名中获取短“域名”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1214512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get short "domain name" from dns domain name?
提问by Max Schmeling
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.
域名有两种不同的“版本”。第一个是我所说的 DNS 域名,它类似于company.int(对于用户 [email protected]),第二个类似于prefixname(对于用户 prefixname\max),它们都指的是相同的事物。
My question is, given "company.int", how do I convert that to "prefixname"?
我的问题是,给定“company.int”,如何将其转换为“prefixname”?
EDIT: Or given a System.DirectoryServices.ActiveDirectory.Domain object, how do I get the prefixname?
编辑:或者给定 System.DirectoryServices.ActiveDirectory.Domain 对象,我如何获得前缀名?
EDIT2: Also, is there a name for the "prefixname" other than that? I never know what to call it.
EDIT2:另外,除此之外还有“前缀名”的名称吗?我永远不知道该怎么称呼它。
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).
EDIT3:我尝试获取的值与 Windows 登录屏幕上显示的“登录”值相同(其中列出了域和您的计算机)。
EDIT4: I've figured out I can get the value by doing the following:
EDIT4:我发现我可以通过执行以下操作来获得价值:
SecurityIdentifier sid = GetCurrentUserSID();
string prefixName = sid.Translate(typeof(NTAccount)).Value.Split('\')[0];
Does anyone know of a better method to get this name?
有谁知道获得这个名字的更好方法?
回答by marc_s
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).
您基本上使用“mydomain.com”来调用它,并且应该取回netbios 域名,例如“MYDOMAIN”(通常)。
Marc
马克
回答by Russ Bradberry
are you looking for System.DirectoryServices.DirectoryEntry.Path?
您在寻找System.DirectoryServices.DirectoryEntry.Path吗?
and the prefixname is just called domain
而前缀名只是被称为域
EDIT:what about Environment.UserDomainName?
编辑:Environment.UserDomainName 怎么样?
回答by Martin v. L?wis
To my knowledge, prefixnameis always the first label of company.int(i.e. company).
据我所知,prefixname始终是company.int(即company)的第一个标签。