Welcome to TechNet Blogs Sign in | Join | Help

Microsoft Windows DHCP Team Blog

The world's most deployed DHCP Server! Deploy and discuss about your fav. server, here!
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, %d\n",error);

           

            printf(" IP   %x\n", clientInfo->ClientIpAddress);

 

 

}

/*

 

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

IP   6e6e6e32

 

*/

 

Manu Jeewani,

Windows Enterprise Networking

Posted: Friday, October 26, 2007 12:19 PM by teamdhcp

Comments

rupj said:

Heh, I actually figured this one out on my own by reverse engineering the DHCP ESE DB.

I'm glad DHCP team has come around to explaining its API.  Hope to see more post like this one.

# October 27, 2007 1:33 PM

Dan said:

Hi,

I'm trying to use the example the retrieve a client IP based on MAC. DhcpGetClientInfo always return error code 1783 (0x000006F7: The stub received bad data). Do you have any ideea what might be going on?

Thanks,

Dan.

# November 16, 2007 1:42 PM

VladZ said:

Hello,

This example works fine in Win XP(SP3) but not works in Vista (Business, SP1). It returns error code 1783. What I need to do for get the correct result in Vista?

# September 1, 2008 8:47 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker