本文介绍了如何获得在C#中的DHCP信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得DHCP选项在C#15的信息。我不想通过dhcpsapi.dll虽然打电话,因为我不想被限于的Windows的DHCP服务器做。有一些其他的方式,通过C#来获取DHCP信息,还是我将不得不handcode呢?

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?

推荐答案

您可以使用WMI和Win32_NetworkAdapterConfiguration类。
一个可用字段返回的DNSHOSTNAME这似乎是DHCP选项15。

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

这篇关于如何获得在C#中的DHCP信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 03:12