Obtain the MAC address of a remote Nic

Source: Internet
Author: User

First, add # include "nb30.h" to the header file definition"
# Pragma comment (Lib, "netapi32.lib ")
Typedef struct _ astat _
{
Adapter_status adapt;
Name_buffer namebuff [30];
} Astat, * pastat;

You can call this operation to obtain the MAC address of the remote NIC:
Cstring getmacaddress (cstring snetbiosname)
{
Astat adapter;
 
NCB;
Uchar uretcode;
 
Memset (& NCB, 0, sizeof (NCB ));
NCB. ncb_command = ncbreset;
NCB. ncb_lana_num = 0;
 
Uretcode = NetBIOS (& NCB );
 
Memset (& NCB, 0, sizeof (NCB ));
NCB. ncb_command = ncbastat;
NCB. ncb_lana_num = 0;
 
Snetbiosname. makeupper ();
 
Fillmemory (NCB. ncb_callname, ncbnamsz-1, 0x20 );
 
Strcpy (char *) NCB. ncb_callname, (lpctstr) snetbiosname );
 
NCB. ncb_callname [snetbiosname. getlength ()] = 0x20;
NCB. ncb_callname [ncbnamsz] = 0x0;
 
NCB. ncb_buffer = (unsigned char *) & adapter;
NCB. ncb_length = sizeof (adapter );
 
Uretcode = NetBIOS (& NCB );

Cstring smacaddress;
 
If (uretcode = 0)
{
Smacaddress. Format (_ T ("% 02x % 02x % 02x % 02x % 02x % 02x "),
Adapter. Adapt. adapter_address [0],
Adapter. Adapt. adapter_address [1],
Adapter. Adapt. adapter_address [2],
Adapter. Adapt. adapter_address [3],
Adapter. Adapt. adapter_address [4],
Adapter. Adapt. adapter_address [5]);
}
Return smacaddress;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.