3

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?

evilfred
  • 2,314
  • 4
  • 29
  • 44
  • Looks like a duplicate of http://stackoverflow.com/questions/3986982/dhcp-request-packet-in-c, which suggests you may need to code it yourself to the RFCs – Chris Dickson Jan 10 '11 at 19:20
  • Here is an example in Power Shell http://www.indented.co.uk/index.php/2010/02/17/dhcp-discovery/, that you could convert to C#. – Zachary Jan 10 '11 at 19:33
  • Do you want to know the active domainname (option 15) on your local machine, or do you want to query dhcp servers on the network to see what they provide? – sisve Jan 10 '11 at 20:40
  • updated powershell link: https://www.indented.co.uk/dhcp-discovery/ @Zachary – Erdogan Kurtur May 31 '21 at 08:40

1 Answers1

0

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);
}
Spaceghost
  • 6,835
  • 3
  • 28
  • 42