Enviroment.MachineName返回短名称:
public static string GetCurrentMachineName()
{
return GetMachineName(Environment.MachineName); //returns hostname
}
我的主机名很短:shortName
和全名:shortName.company.local
。
所以,当我拨打GetCurrentMachineName()
时,我只获得shortName
而不是'shortName.company.local'。
什么可能是错的?
P.S .:
它对我不起作用:例如,我的主机名是hostname1
。
我当前网络的朋友的主机名为hostname2
。所以,当我执行这段代码时:
return System.Net.Dns.GetHostEntry("").HostName;
主机名2解析为hostname2.company.local
,hostname1
解析为我的主机名。
答案 0 :(得分:3)
使用此Dns.GetHostEntry("").HostName
获取完整的主机名
public static string GetCurrentMachineName()
{
return System.Net.Dns.GetHostEntry("").HostName; //returns hostname
}
答案 1 :(得分:0)
我解决了,我的问题:
刷新DNS缓存
ipconfig / flushdns
清除我的hosts
文件。
谢谢你的帮助!