Finding Client Info based on MAC address.

There is a DHCP Server management API DhcpGetClientInfo() with which DHCPUser can get the information about DHCP Clients.

 There are three way to figure out the information for the client with the above API.

The first one is by specifing ClientIPAddress in DHCP_SEARCH_INFO structure.

The second way is by specifing the ClientName in DHCP_SERACH_INFO structure.

 The third one and the trickest one is by specify the MAC addess. For particular MAC address there can be more the one address assigned to client in differnt subnets so while doing the search the API caller should specify in which subnet one wants to perform the serach. For this he needs to create the client UID. 

 The client UID is created in this way.

[Subnet address in which he wants to perform the search for the client]*+[01]+[MAC]

The following is the sample code for doing this.

 

#include"stdio.h"

#include"windows.h"

#include"dhcpsapi.h"

main()

{

int error;

DHCP_SEARCH_INFO dhcpSInfo;

DHCP_CLIENT_INFO *clientInfo;

WCHAR *server=L"127.0.0.1";

BYTE Mac[11];

DWORD ipAddress;

int i;

Mac[0] = 0x00; /// Subnet address in host order.

Mac[1] = 0x00;

Mac[2] = 0x00;

Mac[3] = 0x6e;

Mac[4] = 0x01; ///-à Hardware address type, this is the default value.

Mac[5] = 0x00; ///--à My MAC bytes start from here (00 14 38 c1 c6 b3 )

Mac[6] = 0x14;

Mac[7] = 0x38;

Mac[8] = 0xc1;

Mac[9] = 0xc6;

Mac[10] =0xb3;

dhcpSInfo.SearchType = DhcpClientHardwareAddress;

dhcpSInfo.SearchInfo.ClientHardwareAddress.DataLength=11;

dhcpSInfo.SearchInfo.ClientHardwareAddress.Data=Mac;

error = DhcpGetClientInfo(server,&dhcpSInfo,&clientInfo);

printf("Error, %dn",error);

printf(" IP %xn", clientInfo->ClientIpAddress);

}

/*

The output I got by executing this particular code on was Error, 0

IP 6e6e6e32

*/

Manu Jeewani,

Windows Enterprise Networking