/// <summary>
/// The DhcpGetClientInfo function returns information about a specific DHCP client.
/// </summary>
/// <param name="ServerIpAddress">[in] Unicode string that specifies the IP address of the DHCP server.</param>
/// <param name="SearchInfo">[in] DHCP_SEARCH_INFO structure that contains the parameters for the search. </param>
/// <param name="ClientInfo">[out] Pointer to a DHCP_CLIENT_INFO structure that contains information describing the DHCP client that most closely matches the provided search parameters. If no client is found, this parameter will be null.</param>
/// <returns>This function returns ERROR_SUCCESS upon a successful call. Otherwise, it returns one of the DHCP Server Management API Error Codes.</returns>
[DllImport("dhcpsapi.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern UInt32 DhcpGetClientInfo(
String ServerIpAddress,
ref DHCP_SEARCH_INFO SearchInfo,
out IntPtr ClientInfo);
Declare Function DhcpGetClientInfo Lib "dhcpsapi.dll" (TODO) As TODO
Do you know one? Please contribute it!
None.
Please add some!
static void Main()
{
String ServerIpAddress = "192.168.0.250";
UInt32 DHCPResult = 0;
try
{
DHCP_SEARCH_INFO searchInfo = new DHCP_SEARCH_INFO();
DHCP_SEARCH_INFO_TYPE searchInfoType = DHCP_SEARCH_INFO_TYPE.DhcpClientIpAddress;
searchInfo.SearchType = searchInfoType;
searchInfo.ClientIpAddress = ConvertIPAddress("192.168.0.10");
IntPtr pClientInfo;
DHCPResult = DhcpGetClientInfo(ServerIpAddress, ref searchInfo, out pClientInfo);
if (DHCPResult == 0 && pClientInfo != IntPtr.Zero)
{
DHCP_CLIENT_INFO clientInfo = (DHCP_CLIENT_INFO)Marshal.PtrToStructure(pClientInfo, typeof(DHCP_CLIENT_INFO));
Console.WriteLine(DHCPResult.ToString() + " Client Info: " + clientInfo.ClientName);
}
else
{
Console.WriteLine(DHCPResult.ToString() + " Failed");
}
}
public static UInt32 ConvertIPAddress(string ipAddress)
{
char[] dot = ".".ToCharArray();
char[] zero = "0".ToCharArray();
string[] Octets = ipAddress.Split(dot[0]);
string HexIP = "";
foreach (string Octet in Octets)
{
HexIP += Convert.ToString(Convert.ToInt16(Octet), 16).PadLeft(2, zero[0]);
}
return Convert.ToUInt32(HexIP, 16);
}