# Include <nb30.h> # pragma comment (Lib, "netapi32.lib") typedef struct _ astat _ {adapter_status adapt; name_buffer namebuff [30];} astat, * pastat; astadapter; // define a variable for storing the returned Nic information // input parameter: lana_num is the NIC number, generally starting from 0, however, in Windows 2000, it is not necessarily the consecutively assigned void getmac_one (INT lana_num) {NCB; uchar uretcode; memset (& NCB, 0, sizeof (NCB); NCB. ncb_command = ncbreset; NCB. ncb_lana_num = lana_num; // specify the nic id // first, send an ncbreset command to the selected Nic to initialize uretcode = NetBIOS (& NCB ); // printf ("The ncbreset return code is: 0x % x \ n", uretcode); memset (& NCB, 0, sizeof (NCB); NCB. ncb_command = ncbastat; NCB. ncb_lana_num = lana_num; // specify the NIC number strcpy (char *) NCB. ncb_callname, "*"); NCB. ncb_buffer = (unsigned char *) & adapter; // specify the variable NCB where the returned information is stored. ncb_length = sizeof (adapter); // you can then send the ncbastat command to obtain the NIC information uretcode = NetBIOS (& NCB); // printf ("The ncbastat return code is: 0x % x \ n ", uretcode); If (uretcode = 0) {// format the nic mac address into a common hexadecimal format, for example, 0010-a4e4-5802printf ("the Ethernet number [% d] is: % 02x-% 02x-% 02x-% 02x-% 02x-% 02x \ n", lana_num, 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]) ;}} int main () {NCB; uchar uretcode; lana_enum; memset (& NCB, 0, sizeof (NCB); NCB. ncb_command = ncbenum; NCB. ncb_buffer = (unsigned char *) & lana_enum; NCB. ncb_length = sizeof (lana_enum); // send the ncbenum command to the NIC to obtain the NIC information of the current machine, uretcode = NetBIOS (& NCB); // printf ("The ncbenum return code is: 0x % x \ n", uretcode ); if (uretcode = 0) {// printf ("Ethernet count is: % d \ n", lana_enum.length); // For each Nic, enter the ID of the network card and obtain the MAC address for (INT I = 0; I <lana_enum.length; ++ I) getmac_one (lana_enum.lana [I]);} return 0 ;}