问题
I would like to get DHCP Option 15 information in C#. I do not want to call through dhcpsapi.dll though, because I don't want to be limited to just Windows DHCP servers. Is there some other way to get DHCP information through C# or am I going to have to handcode this?
回答1:
You can use WMI and the Win32_NetworkAdapterConfiguration class. One of the available fields returned is DNSHostName which seems to be DHCP option 15.
ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'") ;
ManagementObjectCollection queryCollection = query.Get();
foreach( ManagementObject mo in queryCollection )
{
string dnsName = (string[])mo["DNSHostName"];
Console.WriteLine("IP Address: {0}", ipaddress);
}
来源:https://stackoverflow.com/questions/4650540/how-to-get-dhcp-information-in-c