I have been searching for quite a while and cannot seem to find a working DHCP Client implementation example in C#. I am brand spankin' new to Network Programming, but am doing some research that requires me to write a manual DHCP client and to implement Auto-IP if there is no DHCP server. i want to send DHCP discover packets using C# to get anther IP address
Asked
Active
Viewed 1,778 times
1 Answers
1
DHCP uses UDP as transport protocol, so you need to send UDP datagram with DHCP payload.
How to send UDP is already answered here: Sending UDP Packet in C#
DHCP frame fromat is described in many places on the internet e.g. http://www.tarunz.org/~vassilii/TAU/protocols/dhcp/frame.htm
Here is another example DHCP server: http://www.codeproject.com/Articles/20431/A-Small-DHCP-Server-Using-UDP-With-Asynchronous-Ca
Unfortunately it seems like there is not C# library for querying DHCP server, but you may use WinAPI via P/Invoke: DHCP Client API
EDIT: After bit of searching, here is C# wrapper for WinAPI calls: http://www.rupj.net/portfolio/dhcp-web-services.html and http://www.pinvoke.net/default.aspx/dhcpsapi/DhcpGetClientInfo.html

Community
- 1
- 1

csharpfolk
- 4,124
- 25
- 31