【发布时间】:2016-10-10 08:29:32
【问题描述】:
Enviroment.MachineName 返回短名称:
public static string GetCurrentMachineName()
{
return GetMachineName(Environment.MachineName); //returns hostname
}
我有短主机名:shortName 和全名:shortName.company.local。
所以,当我打电话给GetCurrentMachineName() 时,我只得到shortName 而不是'shortName.company.local'。
有什么问题?
附:
这对我不起作用:例如,我的主机名是hostname1。
我在当前网络的朋友有一个名为hostname2 的主机名。所以,当我执行这段代码时:
return System.Net.Dns.GetHostEntry("").HostName;
使用 hostname2 它解析为 hostname2.company.local 和 hostname1 解析为我的主机名。
【问题讨论】: