DHCP 地址 255.255.255.255

发布于 2024-12-14 04:25:38 字数 373 浏览 4 评论 0原文

我使用以下代码从我的网络接口之一获取 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撧情箌佬 2024-12-21 04:25:38

地址255.255.255.255是一个广播地址,DHCP协议使用它来广播可用性数据包。当您不使用 DHCP 时,这是分配为 DHCP 服务器的地址,因为它将允许网络自动发现网络上的任何 DHCP 服务器(通常是路由器)。

您可以使用它来检查 DHCP:

bool isDhcp = networkInterface.GetIPProperties()
                              .GetIPv4Properties()
                              .IsDhcpEnabled;

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:

bool isDhcp = networkInterface.GetIPProperties()
                              .GetIPv4Properties()
                              .IsDhcpEnabled;
呆橘 2024-12-21 04:25:38

它不是“真实”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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文