【发布时间】:2021-01-27 17:18:46
【问题描述】:
我正在尝试从 ipconfig /all 中查找网络接口名称。例如,如果 ipconfig /all 输出是:
Ethernet adapter Npcap Loopback Adapter:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Npcap Loopback Adapter
Physical Address. . . . . . . . . : 01-00-4C-5F-5F-50
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Autoconfiguration IPv4 Address. . : 169.254.183.10(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . :
NetBIOS over Tcpip. . . . . . . . : Enabled
我想打印“以太网适配器 Npcap 环回适配器”。这是我尝试过的:
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in interfaces)
{
richTextBox1.AppendText(adapter.Name);
}
但它只打印“以太网”而不是完整的东西。
【问题讨论】:
-
查看 pinvoke : pinvoke.net/default.aspx/netapi32.NetServerGetInfo
-
你试过
richTextBox1.AppendText($"{adapter.Name} {adapter.Description}");吗? -
@jdweng 不,这些都没有帮助
-
@ɐsɹǝʌǝɔıʌ 描述与名称不同
标签: c# networking command-line