我正在使用以下代码从我的网络接口(interface)之一获取 DHCP 服务器地址:
System.Net.NetworkInformation.NetworkInterface networkInterface;
// ... get one of the network interfaces
var properties = networkInterface.GetIPProperties();
var addresses = properties.DhcpServerAddresses;
我的网络接口(interface)设置为一个固定地址(不是由 DHCP 分配的),我从该代码中获得一个地址,它是 255.255.255.255。谁能告诉我为什么?以及如何检查网络接口(interface)是使用 DHCP 还是固定地址。
最佳答案
地址 255.255.255.255
是一个广播地址,DHCP 协议(protocol)使用它来广播可用性数据包。当您不使用 DHCP 时,这是分配为 DHCP 服务器的地址,因为它将允许网络自动发现网络上的任何 DHCP 服务器(通常是路由器)。
您可以使用它来检查 DHCP:
bool isDhcp = networkInterface.GetIPProperties()
.GetIPv4Properties()
.IsDhcpEnabled;
关于c# - DHCP 地址 255.255.255.255,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8049720/