DHCP 地址 255.255.255.255
我使用以下代码从我的网络接口之一获取 DHCP 服务器地址:
System.Net.NetworkInformation.NetworkInterface networkInterface;
// ... get one of the network interfaces
var properties = networkInterface.GetIPProperties();
var addresses = properties.DhcpServerAddresses;
我的网络接口设置为固定地址(不是由 DHCP 分配),我从该代码获取一个地址,它是 255.255.255.255。谁能告诉我为什么?如何检查网络接口是否使用 DHCP 还是固定地址。
I'm using the following code to get DHCP server address from one of my network interfaces:
System.Net.NetworkInformation.NetworkInterface networkInterface;
// ... get one of the network interfaces
var properties = networkInterface.GetIPProperties();
var addresses = properties.DhcpServerAddresses;
My network interface is set to a fixed address (not assigned by DHCP) and I'm getting one address from that code, it's 255.255.255.255. Anybody can tell me why? And how can I check if a network interface uses a DHCP or fixed address.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
地址
255.255.255.255
是一个广播地址,DHCP协议使用它来广播可用性数据包。当您不使用 DHCP 时,这是分配为 DHCP 服务器的地址,因为它将允许网络自动发现网络上的任何 DHCP 服务器(通常是路由器)。您可以使用它来检查 DHCP:
The address
255.255.255.255
is a broadcast address, which is used by the DHCP protocol to broadcast availability packets. When you're not using DHCP this is the address assigned as a DHCP server, because it will allow the network to automatically discover any DHCP servers (usually routers) on the network.You can use this to check for DHCP:
它不是“真实”IP 地址,因为它无法分配给主机。它简单的意思就是“到处广播”。
我认为可以安全地假设,当您发现 255.255.255.255 作为 DHCP 服务器地址时,您正在查询的适配器具有固定的 IP 地址,或 APIPA(当适配器设置为 DHCP 客户端,但在预设时间内没有 DHCP 服务器响应时,会发生这种情况)。
但 @Polynomial 提到的 IsDhcpEnabled 属性更安全。
It isn't a 'real' IP address as it can't be assigned to a host. It simply means "broadcast everywhere".
I think it's safe to assume that when you find 255.255.255.255 as DHCP server address, the adapter you're querying has a fixed IP address, or APIPA (which happens when an adapter is set as DHCP client, but no DHCP server has responded for a preset period of time).
But the
IsDhcpEnabled
property that @Polynomial mentions is safer to rely on.