如何在C#中以编程方式检索主Dns后缀?
Run Code Online (Sandbox Code Playgroud)C:\Users\jdoe>ipconfig /all Windows IP Configuration Host Name . . . . . . . . . . . . : ABC-PC --->Primary Dns Suffix . . . . . . . : mdanshin.co.za<--- Node Type . . . . . . . . . . . . : Hybrid IP Routing Enabled. . . . . . . . : No WINS Proxy Enabled. . . . . . . . : No DNS Suffix Search List. . . . . . : mdanshin.co.za
所以,Alex K 的答案不正确(抱歉)。这将为您提供连接特定的 DNS 信息,该信息对于每个适配器可能不同。考虑下面的配置。一个适配器会给出不同的答案。
正确答案是:
var primaryDnsSuffix = IPGlobalProperties.GetIPGlobalProperties().DomainName;
Run Code Online (Sandbox Code Playgroud)
这将返回“Primary Dns Suffix”行中的值
IPInterfaceProperties.DnsSuffix 属性
多宿主 ipconfig /all 输出:
Run Code Online (Sandbox Code Playgroud)Windows IP Configuration Host Name . . . . . . . . . . . . : BOB Primary Dns Suffix . . . . . . . : fred.george.com Node Type . . . . . . . . . . . . : Peer-Peer IP Routing Enabled. . . . . . . . : No WINS Proxy Enabled. . . . . . . . : No DNS Suffix Search List. . . . . . : fred.george.com george.com PPP adapter Harry: Connection-specific DNS Suffix . : fred.george.com Description . . . . . . . . . . . : Harry Physical Address. . . . . . . . . : DHCP Enabled. . . . . . . . . . . : No Autoconfiguration Enabled . . . . : Yes IPv4 Address. . . . . . . . . . . : 192.168.1.2(Preferred) Subnet Mask . . . . . . . . . . . : 255.255.255.255 Default Gateway . . . . . . . . . : 0.0.0.0 DNS Servers . . . . . . . . . . . : 192.168.1.1 Primary WINS Server . . . . . . . : 192.168.1.100 Secondary WINS Server . . . . . . : 192.168.1.101 NetBIOS over Tcpip. . . . . . . . : Enabled Ethernet adapter Ethernet 2: Connection-specific DNS Suffix . : ron.george.com Description . . . . . . . . . . . : Realtek USB GbE Family Controller #2 Physical Address. . . . . . . . . : 6B-21-CD-65-AC-25 DHCP Enabled. . . . . . . . . . . : Yes Autoconfiguration Enabled . . . . : Yes IPv4 Address. . . . . . . . . . . : 192.168.1.3(Preferred) Subnet Mask . . . . . . . . . . . : 255.255.240.0 Lease Obtained. . . . . . . . . . : Friday, August 30, 2019 10:29:34 AM Lease Expires . . . . . . . . . . : Thursday, September 05, 2019 2:36:12 PM Default Gateway . . . . . . . . . : DHCP Server . . . . . . . . . . . : 192.168.1.1 DNS Servers . . . . . . . . . . . : 192.168.1.102 192.168.1.103 NetBIOS over Tcpip. . . . . . . . : Disabled Connection-specific DNS Suffix Search List : george.com
| 归档时间: |
|
| 查看次数: |
1256 次 |
| 最近记录: |