문제
.net 2.0에 내 코드가 실행되는 컴퓨터의 네트워크 별칭을 검색할 수 있는 방법이 있나요?특히, 내 작업 그룹에서 내 컴퓨터를 //jekkedev01로 인식하는 경우 해당 이름을 프로그래밍 방식으로 검색하려면 어떻게 해야 합니까?
해결책
여러 네트워크 인터페이스가 있을 수 있고 각 인터페이스에는 여러 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;
}
다른 팁
컴퓨터 설명이 필요한 경우 레지스트리에 저장됩니다.
- 열쇠:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters
- 값 이름:
srvcomment
- 데이터 형식:
REG_SZ (string)
AFAIK는 도메인 서버나 PC가 연결된 네트워크와 관련이 없습니다.
네트워크와 관련된 모든 것에는 다음을 사용하고 있습니다.
- NETBIOS 이름:
System.Environment.MachineName
- 호스트 이름:
System.Net.Dns.GetHostName()
- DNS 이름:
System.Net.Dns.GetHostEntry("LocalHost").HostName
PC에 여러 개의 NETBIOS 이름이 있는 경우 확인되는 IP 주소를 기반으로 이름을 그룹화하는 것 외에는 다른 방법을 모릅니다. PC에 여러 네트워크 인터페이스가 있는 경우에도 이 방법은 신뢰할 수 없습니다.
저는 .NET 프로그래머는 아니지만 System.Net.DNS.GetHostEntry 방법이 필요한 것 같습니다.이는 다음의 인스턴스를 반환합니다. IPHostEntry 다음을 포함하는 클래스 별칭 재산.
사용 시스템.환경 수업.NetBios에서 검색되는 시스템 이름을 검색하기 위한 속성이 있습니다.내가 귀하의 질문을 오해하지 않는 한.
또는 내.컴퓨터.이름
제휴하지 않습니다 StackOverflow