c# - DHCP 地址 255.255.255.255

标签 c# networking dhcp

我正在使用以下代码从我的网络接口(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/

相关文章:

linux - 如何让 dhclient 知道 namespace ?

c# - .mdf 文件和跨数据库查询?

c# - 正则表达式匹配.Net

c# - 使用 IoC 容器的合适情况?

linux - 当 DHCP 服务器分配域时,向 DNS-SD 注册哪个域的服务名称?

c - 在没有DHCP的情况下发现默认网关

javascript - 无法清除下拉菜单的文本

Python操作系统错误: A socket operation was attempted to an unreachable network

c# - 自动获取服务器IP给客户端

iphone - iPhone 是否有 3G 连接 "connectable?"使用套接字时 3g/wifi 是否透明?