Open ode2code95 opened 2 weeks ago
Tagging subscribers to this area: @dotnet/ncl See info in area-owners.md if you want to be subscribed.
this may be difficult to get it working on all platforms as the info may be proprietary to given implementation.
I did just discover this afternoon another workaround using the UnicastIPAddressInformation.DhcpLeaseLifetime
property. Somehow I had missed this one yesterday. This is the number of seconds until lease expiration, and we can calculate the DateTime from that if we want it.
This property is annotated as Windows-specific.
I have not tested it yet, but I'm assuming if we read this property on the interface's IPv4 address we should get the answer we are looking for. I'll admit that I do not understand DHCP with regards to IPv6 yet.
Background and motivation
We should be able to easily retrieve all of the properties displayed with
ipconfig /all
with the classes in theSystem.Net.NetworkInformation
namespace:The
IPv4InterfaceProperties
class inSystem.Net.NetworkInformation
yields a number of the IPv4 metrics for network adapters. It includesIsDhcpEnabled
but not theDhcpLeaseExpires
or theDhcpLeaseObtained
properties from WMI. The current workaround is to query WMI directly using theWin32_NetworkAdapterConfiguration
class.API Proposal
API Usage
Alternative Designs
Perhaps an
IPAddress
instance has better access to these properties?Risks
None that I can see. We are already querying WMI for other properties from the
Win32_NetworkAdapterConfiguration
class.