2008-09-12 8 views
1

.net 2.0에서 내 코드가 실행되는 컴퓨터의 네트워크 별칭을 검색 할 수 있습니까? 특히 내 작업 그룹이 내 컴퓨터를 // jekkedev01로 보는 경우 프로그래밍 방식으로 해당 이름을 검색하려면 어떻게해야합니까?.net에서 네트워크 별칭 찾기.

답변

2

각 네트워크 인터페이스에는 여러 개의 IP가있을 수 있으며 하나의 IP에는 여러 개의 이름이있을 수 있으므로 여러 개의 IP 주소가있을 수 있습니다.

당신이 당신의 DNS 서버가 컴퓨터를 알고있는 모든 이름을 알고 싶다면

,이 같은 그들 모두를 통해 반복 할 수 있습니다

로컬 컴퓨터 이름입니다
public ArrayList GetAllDnsNames() { 
    ArrayList names = new ArrayList(); 
    IPHostEntry host; 
    //check each Network Interface 
    foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) { 
    //check each IP address claimed by this Network Interface 
    foreach (UnicastIPAddressInformation i in nic.GetIPProperties().UnicastAddresses) { 
     //get the DNS host entry for this IP address 
     host = System.Net.Dns.GetHostEntry(i.Address.ToString()); 
     if (!names.Contains(host.HostName)) { 
     names.Add(host.HostName); 
     } 
     //check each alias, adding each to the list 
     foreach (string s in host.Aliases) { 
     if (!names.Contains(s)) { 
      names.Add(s); 
     } 
     } 
    } 
    } 
    //add "simple" host name - above loop returns fully qualified domain names (FQDNs) 
    //but this method returns just the machine name without domain information 
    names.Add(System.Net.Dns.GetHostName()); 

    return names; 
} 
0

System.Environment 클래스를 사용하십시오. NetBios에서 검색된 시스템 이름을 검색 할 수있는 특성이 있습니다. 당신의 질문을 오해하지 않는 한.

+0

. 필요한 것은 도메인 서버가 컴퓨터에 연결 한 네트워크 별칭입니다. –

0

또는 컴퓨터 설명을해야하는 경우 My.Computer.Name

1

, 그것은 레지스트리에 저장됩니다

  • 키 : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters
  • 값 이름 : srvcomment
  • 데이터 형식 : REG_SZ (string)

AFAIK AFAIK는 아무 dom과도 관련이 없습니다. ain 서버 또는 PC가 연결된 네트워크에 연결하십시오.

  • NETBIOS 이름 : System.Environment.MachineName
  • 호스트 이름 : System.Net.Dns.GetHostName()
  • DNS 이름 : System.Net.Dns.GetHostEntry("LocalHost").HostName

PC가 만약

네트워크에 관련된 아무것도 들어

, 나는 다음을 사용하고 있습니다 여러 NETBIOS 이름을 가지고 있지만 다른 방법은 모르지만 해결할 IP 주소를 기반으로 이름을 그룹화합니다. PC에 여러 네트워크 인터페이스가있는 경우

관련 문제