Get NetBIOS and DNS computer names


Jump to: navigation, search
C# Code Snippets

C# Source Code Bank

See also …
edit

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

static string GetLocalHostName ()
{
   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;
}

Visual C# Best Practices

Avoid using pointers in unsafe code to access Windows data.



Personal tools