开发者

How to get DHCP information in C#?

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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜