Unmanaged, but working:
HTH
Axel
#include "stdafx.h"
#include <windows.h>
#include <malloc.h>
#include <Iphlpapi.h>
#pragma comment(lib, "Iphlpapi.lib")
void printIPAddresses ()
{
PMIB_IPADDRTABLE table;
DWORD size=0;
GetIpAddrTable( 0, &size, TRUE );
table = (PMIB_IPADDRTABLE ) alloca( size);
GetIpAddrTable(
table,
&size,
TRUE );
for ( int i=0; i<table->dwNumEntries; i++ )
{
int ipAdr[4];
ipAdr[3] = ( table->table[i].dwAddr
) >> 24;
ipAdr[2] = ( table->table[i].dwAddr & 0xffffff ) >> 16;
ipAdr[1] = ( table->table[i].dwAddr & 0xffff ) >> 8;
ipAdr[0] = ( table->table[i].dwAddr & 0xff );
printf( "%d.%d.%d.%d\n", ipAdr[0], ipAdr[1], ipAdr[2],
ipAdr[3] );
}
}
int _tmain(int argc, _TCHAR* argv[])
{
printIPAddresses();
return 0;
}
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.