Search

Get NetBIOS and DNS computer names

This C# code snippet obtains the NetBIOS and DNS computer names of the local computer.
using System;
 
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;
}