I would like to get DH开发者_JAVA技巧CP 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?
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);
}
精彩评论