Вариант 1 Вот исходник моей функции для опpеделения МАС адpеса. UCHAR MYLIBAPI GetAdapterID(char *Name, // NetBIOS имя станции UINT lana_num, CARDID *ID) // 6 байтовый массив { UCHAR rc = 0; UCHAR Status[256]; while( lstrlen(Name) - 15) lstrcat(Name, " "); memset(&SNcb, 0, sizeof(NCB)); SNcb.ncb_command = NCBASTAT; SNcb.ncb_buffer = (LPSTR)Status; SNcb.ncb_length = 256; lstrcpy(SNcb.ncb_callname, Name); SNcb.ncb_lana_num = lana_num; rc = Netbios( &SNcb ); if(rc ==0){ memcpy(ID, Status, 6); } return(SNcb.ncb_cmd_cplt); } Это под Win32. Конечно должен быть пpотокол NetBIOS, но он в фоpточках и так необходим. Вариант2 #include <windows.h> #include <winsock.h> #include <wsipx.h> #include <wsnwlink.h> #include <stdio.h> void main() { int iAdapters,iOpt=sizeof(iAdapters),iSize=sizeof(SOCKADDR_IPX); SOCKET skNum; SOCKADDR_IPX Addr; WSADATA Wsa; if(WSAStartup(0x0101,&Wsa)) return; if((skNum=socket(AF_IPX,SOCK_DGRAM,NSPROTO_IPX))!=INVALID_SOCKET) { memset(&Addr,0,sizeof(Addr)); Addr.sa_family=AF_IPX; if(bind(skNum,(SOCKADDR *)&Addr,iSize)!=SOCKET_ERROR) { if(getsockopt(skNum,NSPROTO_IPX,IPX_MAX_ADAPTER_NUM, (char *)&iAdapters,&iOpt)!=SOCKET_ERROR) { while(iAdapters) { IPX_ADDRESS_DATA Data; memset(&Data,0,sizeof(Data)); Data.adapternum=iAdapters-1; iOpt=sizeof(Data); if(getsockopt(skNum,NSPROTO_IPX,IPX_ADDRESS,(char *)&Data,&iOpt)!=SOCKET_ERROR) { printf("Addr: %02X%02X%02X%02X:%02X%02X%02X%02X%02X%02X\n", (int)Data.netnum[0],(int)Data.netnum[1],(int)Data.netnum[2], (int)Data.netnum[3],(int)Data.netnum[4],(int)Data.netnum[5], (int)Data.netnum[6],(int)Data.netnum[7],(int)Data.netnum[8], (int)Data.netnum[9]); } iAdapters--; } } } closesocket(skNum); } WSACleanup(); } Вариант 3 #include <windows.h> #include <wincon.h> #include <stdlib.h> #include <stdio.h> #include <time.h> typedef struct _ASTAT_ { ADAPTER_STATUS adapt; NAME_BUFFER NameBuff [30]; }ASTAT, * PASTAT; ASTAT Adapter; void main (void) { NCB Ncb; UCHAR uRetCode; char NetName[50]; memset( &Ncb, 0, sizeof(Ncb) ); Ncb.ncb_command = NCBRESET; Ncb.ncb_lana_num = 0; 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 = 0; strcpy( Ncb.ncb_callname, "* " ); Ncb.ncb_buffer = (char *) &Adapter; Ncb.ncb_length = sizeof(Adapter); uRetCode = Netbios( &Ncb ); printf( "The NCBASTAT return code is: 0x%x \n", uRetCode ); if ( uRetCode == 0 ) { printf( "The Ethernet Number is: %02x%02x%02x%02x%02x%02x\n", 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] ); } } |