[ACCEPTED]-How do I find the fully qualified hostname of my machine in C#?-environment-variables
Accepted answer
You may be able to get the whole DNS string 5 like this:
System.Net.Dns.GetHostEntry("").HostName
We don't have full fledged DNS 4 names where I work, but it does give me 3 a three level faux domain name instead of 2 just the hostname.
Edit 2011/03/17: Incorporated 1 changes suggested by mark below.
I used this very similar method:
var serverName = System.Environment.MachineName; //host name sans domain
var fqhn = System.Net.Dns.GetHostEntry(serverName).HostName; //fully qualified hostname
0
If the above doesn't work, you can also 1 try retrieving it from the environment:
var dnsName = new StringBuilder();
dnsName.Append(Environment.GetEnvironmentVariable("COMPUTERNAME")).Append(".");
dnsName.Append(Environment.GetEnvironmentVariable("USERDNSDOMAIN"));
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.