65.9K
CodeProject is changing. Read more.
Home

Finding Computer Name Using C#

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.14/5 (6 votes)

Dec 5, 2011

CPOL
viewsIcon

49754

How to obtain the NetBIOS and DNS computer names of the local computer.

This C# code snippet obtains the NetBIOS and DNS computer names of the local computer.

static string GetName ()
{
   string netBiosName = System.Environment.MachineName;
   
   //return netBiosName;
   // Following method is deprecated
   // string dnsName = 
   //     System.Net.Dns.GetHostByName("LocalHost").HostName;
 
   string dnsName = System.Net.Dns.GetHostName();
   return dnsName;
}