How to get all MAC addresses

zhaozj2021-02-16  41

// NEED INCLUDE FILE: #include

// NEED LIBARY: Netapi32.lib

Int getLollLocaladaptermacaddr (std :: list > & mac)

{

NCB NCB;

LANA_ENUM AdapterList;

MEMSET (& NCB, 0, SIZEOF (NCB));

Ncb.ncb_command = ncbenum;

Ncb.ncb_buffer = (unsigned char *) & adapterlist;

Ncb.ncb_length = sizeof (adapterlist);

NetBIOS (& NCB);

Mac.resize (0);

For (int i = 0; i

{

Struct astat

{

Adapter_Status Adapt;

Name_buffer psz_name [30];

Adapter;

// reset the lan adapter SO That We can begin Querying IT

NCB NCB;

MEMSET (& NCB, 0, SIZEOF (NCB));

Ncb.ncb_command = ncbreset;

Ncb.ncb_lana_num = adapterlist.lana [i];

IF (NetBIOS (& NCB)! = NRC_GOODRET)

CONTINUE;

// prepare to get the adapter status Block

MEMSET (& NCB, 0, SIZEOF (NCB));

Ncb.ncb_command = ncbastat;

Ncb.ncb_lana_num = adapterlist.lana [i];

STRCPY ((char *) ncb.ncb_callname, "*");

MEMSET (& Adapter, 0, Sizeof (Adapter);

Ncb.ncb_buffer = (unsigned char *) & adapter;

Ncb.ncb_length = sizeof (adapter);

// Get the adapter's info and, if this works, return it in standard,

// Colon-Delimited form.

IF (NetBIOS (& NCB) == 0)

{

Std :: Vector v6;

v6.resize (6);

For (int i = 0; i <6; i )

V6 [i] = adapter.adapt.adapter_address [i];

IF (v6 [0] == 0)

{

Std :: List > :: item i = mac.begin ();

For (; i! = mac.end (); i ) if (* i == v6)

Break;

IF (i == mac.end ())

Mac.push_back (v6);

}

}

Else

Break;

}

Return 0;

}

转载请注明原文地址:https://www.9cbs.com/read-27686.html

New Post(0)