Ex : I want something like abc.hyd.mycompany.com. My requirement is to parse this name and initialize appropriate service.
using System.Net;
Dns.GetHostName() // doesn't return fully qualified name it just gives "abc"
Ex : I want something like abc.hyd.mycompany.com. My requirement is to parse this name and initialize appropriate service.
using System.Net;
Dns.GetHostName() // doesn't return fully qualified name it just gives "abc"
You may be able to get the whole DNS string like this:
System.Net.Dns.GetHostEntry("").HostName
We don't have full fledged DNS names where I work, but it does give me a three level faux domain name instead of just the hostname.
Edit 2011/03/17: Incorporated 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 try retrieving it from the environment:
var dnsName = new StringBuilder();
dnsName.Append(Environment.GetEnvironmentVariable("COMPUTERNAME")).Append(".");
dnsName.Append(Environment.GetEnvironmentVariable("USERDNSDOMAIN"));