How to get DHCP information in C#?

狂风中的少年 提交于 2019-12-07 18:52:03

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!