Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Finding Computer Name Using C#

3.14/5 (6 votes)
5 Dec 2011CPOL 49.8K  
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.


C#
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;
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)