liuyuanxun_1983 -> RE: How to get ISA Server's MAC Address? (26.Nov.2005 3:23:02 AM)
|
I have solved this problem illumined by an article from www.codeguru.com. My code is as follow: #include "Iphlpapi.h" DWORD sizeReq = 0 ; PMIB_IFTABLE pInfo = NULL; // Get size information ::GetIfTable(NULL, &sizeReq, FALSE) ; // Allocate required memory pInfo = (PMIB_IFTABLE) new BYTE [sizeReq] ; memset (pInfo, 0, sizeReq) ; DWORD sizeToUse = sizeReq ; // Retrieve network interface information bool result = ( ::GetIfTable( (PMIB_IFTABLE)pInfo,&sizeToUse, FALSE) == NO_ERROR ); if( !result ) { delete (PMIB_IFTABLE)pInfo; pInfo = NULL; } char macStr[100] = {0}; // Print all interface information for( unsigned int index = 0; index < ((PMIB_IFTABLE)pInfo)->dwNumEntries; index ++ ) { // Get interface description MIB_IFROW& details = ((PMIB_IFTABLE)pInfo)->table[index]; // Is this an Ethernet interface? if( (details.dwPhysAddrLen == 6) && (details.dwType == MIB_IF_TYPE_ETHERNET) ) { // Ethernet MAC address printf(" Ethernet: "); } else // Other interface { //printf(" Others: "); } // Format physical address memset(macStr,0,sizeof(macStr)); DWORD j; for ( j = 0 ; j < details.dwPhysAddrLen ; ++j) { sprintf( &macStr[j*3], "%02X-", details.bPhysAddr[j] ); } if ( 0 != j ) { macStr[j*3-1] = '\0'; //we can get mac address here } . }
|
|
|
|