Click here to Skip to main content
15,846,091 members
Articles / Programming Languages / C#
Tip/Trick

Finding Computer Name Using C#

Rate me:
Please Sign up or sign in to vote.
3.14/5 (6 votes)
5 Dec 2011CPOL 48.3K   5   4
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)


Written By
Technical Lead Erls Corporation
India India
I am Dinesh kumar Choudhary by Name, a software Designer and Developer by Work, a Indian Hindu by Religion, Co-Founder of DSFoundation located at http://dsfoundation.wordpress.com by profession, a Loving husband and a Caring Father by Relation.

I have a blog Website at http://dennosecqtinstien.wordpress.com. DSFoundation is the Autonomous body to serve for the management of Local shops located at New Delhi, India. Now a days DSFoundation and its subsidiaries are managed by Erls Corporation, an Another initiative by me and my colleagues, in which i am the another CO-Founder of the Organization. Erls Corporation can be located at http:erlsindia.co.in

Comments and Discussions

 
GeneralMy vote of 1 Pin
Daniel Fisher (lennybacon)20-Mar-14 2:38
Daniel Fisher (lennybacon)20-Mar-14 2:38 
GeneralReason for my vote of 5 Useful Pin
edgartaor21-Feb-12 17:21
edgartaor21-Feb-12 17:21 
Generalyes, a basic one but could be of use to a beginner .. Pin
Denno.Secqtinstien12-Dec-11 19:22
Denno.Secqtinstien12-Dec-11 19:22 
GeneralReason for my vote of 1 Too basic Pin
yuriiv12-Dec-11 17:16
yuriiv12-Dec-11 17:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.