Chitika

Wednesday, February 6, 2013

C# get fully qualified domain name

Use following code snippet to get fully qualified domain name of current machine:



string domainName = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
string hostName = Dns.GetHostName();
string fqdn = "";

if (!hostName.Contains(domainName))
    fqdn = hostName + "." + domainName;
else
    fqdn = hostName;

No comments:

Post a Comment