Obtain the nic mac address
# Include "nb30.h"
# Pragma comment (Lib, "netapi32.lib ")
Void getnetcarmac (void)
{
Typedef struct _ astat _
{
Adapter_status adapt;
Name_buffer namebuff [30];
} Astat, * pastat;
Cstring Strmac;
Astat adapter;
Memset (& adapter, 0, sizeof (astat ));
NCB;
Lana_enum;
Memset (& NCB, 0, sizeof (NCB ));
//
// Obtain the NIC information of the current computer.
//
NCB. ncb_command = ncbenum;
NCB. ncb_buffer = (unsigned char *) & lana_enum;
NCB. ncb_length = sizeof (lana_enum );
Uchar uretcode =: NetBIOS (& NCB );
If (uretcode = 0)
{
//
// Lana_enum.length indicates the number of NICs. It can be considered a nic.
//
For (INT I = 0; I <lana_enum.length; I ++)
{
//
// Initialize the NIC
//
Memset (& NCB, 0, sizeof (NCB ));
NCB. ncb_command = ncbreset;
NCB. ncb_lana_num = lana_enum.lana [0];
Uretcode =: NetBIOS (& NCB );
//
// After initialization, obtain the NIC information. The MAC address is saved in the adapter.
//
Memset (& NCB, 0, sizeof (NCB ));
NCB. ncb_command = ncbastat;
NCB. ncb_lana_num = lana_enum.lana [0];
Strcpy (char *) NCB. ncb_callname ,"*");
NCB. ncb_buffer = (unsigned char *) & adapter;
NCB. ncb_length = sizeof (adapter );
Uretcode =: NetBIOS (& NCB );
If (uretcode = 0)
{
//
// Save the MAC address as a string in Strmac
//
Strmac. 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]);
}
}
}
}
In the 95 and NT systems, this is the only way to check the machine MAC through the program, but after 98 and 2000, the new
The IP helper function makes this process easier.