* 맥에드레스 얻어내기
#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
#include "iprtrmib.h"
#include "tlhelp32.h"
#include "iphlpapi.h"
#pragma comment(lib, "Iphlpapi.lib")
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
/*
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
CString strHello;
strHello.LoadString(IDS_HELLO);
cout << (LPCTSTR)strHello << endl;
}
return nRetCode;
}*/
// GetAdaptersInfo.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//
int _tmain(int argc, _TCHAR* argv[])
{
PIP_ADAPTER_INFO p = NULL;
ULONG len = 0;
DWORD dw = 0;
IP_ADDR_STRING * ns = NULL;
char buf [ 101 ];
char imsi[ 10 ];
len = sizeof( IP_ADAPTER_INFO );
p = (IP_ADAPTER_INFO*) malloc( sizeof( IP_ADAPTER_INFO ) );
dw = ::GetAdaptersInfo( p, &len );
if( dw == ERROR_BUFFER_OVERFLOW )
{
printf( "Error Buffer Overflow\n" );
GlobalFree( p );
p = (IP_ADAPTER_INFO*) malloc( len );
}
if( dw = ::GetAdaptersInfo( p, &len ) == ERROR_SUCCESS )
{
while( p )
{
printf( "Adapter [ %02d ]--------------------\n", p->Index );
printf( "▷ Name: %s\n", p->AdapterName );
printf( "▷ Description: %s\n", p->Description );
printf( "▷ Type: %d\n", p->Type );
memset( buf, NULL, sizeof( buf ) );
memset( buf, NULL, sizeof( imsi ) );
for( int i = 0 ; i < (int)p->AddressLength ; i++ )
{
if( i == p->AddressLength -1 )
wsprintf( imsi, "%02x", p->Address[ i ] );
else
wsprintf( imsi, "%02x-", p->Address[ i ] );
strcat( buf, imsi );
}
printf( "▷ Hardware Address: %s\n", buf );
ns = &p->IpAddressList;
while( ns )
{
printf( "▷ Ip : %s\n" , ns->IpAddress.String );
printf( "▷ Mask: %s\n", ns->IpMask.String );
ns = ns->Next;
}
printf( "\n\n" );
p = p->Next;
}
}
else
{
printf("Call to GetAdaptersInfo failed.\n");
LPVOID lpMsgBuf;
if (FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL )) {
printf("\tError: %s", lpMsgBuf);
}
LocalFree( lpMsgBuf );
}
GlobalFree( p );
return 0;
}
컴파일하기 위해 필요한 라이브러리 파일들
ws2_32.lib
iphlpapi.lib
'프로그래밍 팁 > etc' 카테고리의 다른 글
Context menu (2) | 2011.03.18 |
---|---|
원격 네트워크 MAC주소 구하기 (0) | 2011.03.04 |
DLL에서 다이얼로그 띄우기[핵심] (4) | 2011.01.26 |
try catch (0) | 2011.01.11 |
시간 및 날짜 계산 (0) | 2010.12.31 |