题
有没有一种方法。网2.0发现网络的别名的机,我的代码被上运行?具体地说,如果我的工作组看到我的机器如//jekkedev01,我怎么取这个名字编程方式?
解决方案
因为你可以有多个网络接口,每个可以有多个Ip地址,以及任何单一知识产权可以有多个名称就可以解决,可能有多于一个。
如果你想要知道所有的名字,其中DNS server知道你的机器,你可以循环,通过他们都是这样的:
public ArrayList GetAllDnsNames() {
ArrayList names = new ArrayList();
IPHostEntry host;
//check each Network Interface
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) {
//check each IP address claimed by this Network Interface
foreach (UnicastIPAddressInformation i in nic.GetIPProperties().UnicastAddresses) {
//get the DNS host entry for this IP address
host = System.Net.Dns.GetHostEntry(i.Address.ToString());
if (!names.Contains(host.HostName)) {
names.Add(host.HostName);
}
//check each alias, adding each to the list
foreach (string s in host.Aliases) {
if (!names.Contains(s)) {
names.Add(s);
}
}
}
}
//add "simple" host name - above loop returns fully qualified domain names (FQDNs)
//but this method returns just the machine name without domain information
names.Add(System.Net.Dns.GetHostName());
return names;
}
其他提示
如果你需要计算机的描述中,存在注册表中:
- 关键:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters
- 值名称:
srvcomment
- 数据类型:
REG_SZ (string)
据我所知这没有任何域服务器或网络的电脑。
对于任何有关网络,我使用如下:
- BIOS名称:
System.Environment.MachineName
- 主机名称:
System.Net.Dns.GetHostName()
- DNS name:
System.Net.Dns.GetHostEntry("LocalHost").HostName
如果电脑中有多个BIOS名,我不知道任何其他方法,但以集团名称的基于IP地址他们的决心,即使这是不可靠的电脑中有多个网络接口。
我不是一个。净编程员,但是 系统。网。DNS。GetHostEntry 方法看起来像什么你需要的。它返回的一个实例 IPHostEntry 类,其中包含的 别名 财产。
使用 系统。环境 类。它有一个财产检索的计算机名称,其检索从Bios.除非我误会你的问题。
或者我。计算机。名称
不隶属于 StackOverflow