如何在 C# 中获取完整的主机名?

How to get full host name in C#?

我试过跟着它只给我一个名字。我要全名。 前任。我的系统全名是“sys101.home.homeconsultancy.lan”。下面的代码只给我“sys101”。我想要完整地址“sys101.home.homeconsultancy.lan”。

这是我的代码:

string hostName = System.Net.Dns.GetHostName();

如何获得完整的系统名称?

您可以使用 System.Net.Dns.GetHostEntry:

var fullName = System.Net.Dns.GetHostEntry(string.Empty).HostName;

If an empty string is passed as the hostNameOrAddress argument, then this method returns the IPv4 and IPv6 addresses of the local host.