SystemInformation.ComputerName,Environment.MachineName和Net.Dns.GetHostName之间的区别 [英] Difference between SystemInformation.ComputerName, Environment.MachineName, and Net.Dns.GetHostName

查看:87
本文介绍了SystemInformation.ComputerName,Environment.MachineName和Net.Dns.GetHostName之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所见,在MSDN文档中以及在此处有关SO的其他问题中,有四种获取本地计算机名称的方法。

From what I have seen, in the MSDN documentation and in other questions here on SO, there are four ways to get the local machine name.

Environment.MachineName;
System.Net.Dns.GetHostName();
System.Windows.Forms.SystemInformation.ComputerName;
System.Environment.GetEnvironmentVariable("COMPUTERNAME");

它们返回的方法是否存在差异,或者它们都将返回完全相同的东西时间?

Is there a differnece in what they methods will return or will they all return the exact same thing all of the time?

注意:
我第一次看到此列表:
如何获取本地计算机名称?

推荐答案

Environment.MachineName System.Windows.Forms.SystemInformation.ComputerName 是相同的并返回计算机的NetBIOS名称。此名称限制为15个字符,并且仅在LAN上可见。

Environment.MachineName and System.Windows.Forms.SystemInformation.ComputerName are identical and returns the computer's NetBIOS name. This name is restricted to 15 characters and only visible on the LAN.

System.Net.Dns.GetHostName()返回计算机的基于TCP / IP的主机名。通过在主机名上添加域后缀,您可以跨LAN /在Internet上解析计算机的IP地址。

System.Net.Dns.GetHostName() returns the computer's TCP/IP based hostname. By adding a domain suffix to the hostname you can resolve your computer's IP address across LANs / on the internet.

System.Environment.GetEnvironmentVariable( COMPUTERNAME)返回安装期间设置的计算机名称。最初将NetBIOS和主机名设置为相同的名称。

System.Environment.GetEnvironmentVariable("COMPUTERNAME") returns the computer name set during installation. NetBIOS and hostname are initially set to the same name.

这篇关于SystemInformation.ComputerName,Environment.MachineName和Net.Dns.GetHostName之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆