views:

1594

answers:

2

Ex : I want something like abc.hyd.mycompany.com. My requirement is to parse this name and initialize appropriate service.

use System.net;
Dns.GetHostName() doesn't return fully qualified name it just gives "abc"
+8  A: 

You may be able to get the whole DNS string like this:

System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).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.

R. Bemrose
That worked on my machine :)
Rick Glos
This works. Thanks a lot :)
A: 

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"));
R. Bemrose
This may not work - USERDNSDOMAIN may not be the same as the domain that the machine belongs to.
pduncan