C#에서 내 컴퓨터 이름을 찾을 때 여러 방법이 있다.

Environment.MachineName;
System.Net.Dns.GetHostName();
System.Windows.Forms.SystemInformation.ComputerName;
System.Environment.GetEnvironmentVariable("COMPUTERNAME");

Environment.MachineName

System.Windows.Forms.SystemInformation.ComputerName 

은 동일하다. 우리가 Netbios 네임이라 부르는 호스트 이름을 리턴한다.


System.Net.Dns.GetHostName()

      TCP/IP 상의 컴퓨터 호스트 이름을 리턴.

      컴퓨터의 Netbios 이름은 apple인데 Active Directory 같은 DNS들이 tomato.mydomain.com 이라고 서버를 명명할 경우가 있다.

      이 때 System.Net.Dns.GetHostName()의 결과가 tomato 이다


System.Environment.GetEnvironmentVariable("COMPUTERNAME")

     컴퓨터 설치시 지정한 컴퓨터 이름 리턴. 초기에는 Netbios 이름과 동일

     




+ Recent posts