[ACCEPTED]-How do I find the fully qualified hostname of my machine in C#?-environment-variables
You may be able to get the whole DNS string 5 like this:
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
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"));
More Related questions