Skip to content

Instantly share code, notes, and snippets.

@MareArts
Last active January 3, 2017 11:39
Show Gist options
  • Save MareArts/b7b0d0c7f34e42d136627e97196e4e41 to your computer and use it in GitHub Desktop.
Save MareArts/b7b0d0c7f34e42d136627e97196e4e41 to your computer and use it in GitHub Desktop.
GetMacAddressByIP
http://study.marearts.com/2017/01/get-mac-address-in-mfc.html
CString GetMacAddressbyIP(CString strIP)
{
NCB Ncb;
UCHAR uRetCode;
LANA_ENUM lenum;
int i;
CString strOutput = _T("");
CString string;
ADAPTER_STATUS Adapter;
memset(&Ncb, 0, sizeof(Ncb));
Ncb.ncb_command = NCBENUM;
Ncb.ncb_buffer = (UCHAR *)&lenum;
Ncb.ncb_length = sizeof(lenum);
uRetCode = Netbios(&Ncb);
for (i = 0; i < lenum.length; i++)
{
memset(&Ncb, 0, sizeof(Ncb));
Ncb.ncb_command = NCBRESET;
Ncb.ncb_lana_num = lenum.lana[i];
uRetCode = Netbios(&Ncb);
memset(&Ncb, 0, sizeof(Ncb));
Ncb.ncb_command = NCBASTAT;
Ncb.ncb_lana_num = lenum.lana[i];
strcpy_s((char*)Ncb.ncb_callname, sizeof(Ncb.ncb_callname), (LPSTR)(LPCTSTR)strIP.GetBuffer(0));
Ncb.ncb_buffer = (unsigned char *)&Adapter;
Ncb.ncb_length = sizeof(Adapter);
uRetCode = Netbios(&Ncb);
if (uRetCode == 0)
{
string.Format(_T("%02X:%02X:%02X:%02X:%02X:%02X"),
Adapter.adapter_address[0],
Adapter.adapter_address[1],
Adapter.adapter_address[2],
Adapter.adapter_address[3],
Adapter.adapter_address[4],
Adapter.adapter_address[5]);
strOutput += string;
}
}
return strOutput;
}
@MareArts
Copy link
Author

MareArts commented Jan 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment