Are you sure this works on W98, I could be wrong, but I don't thing the IP helper 
library is available on anything less
than W2K.

Willy.

----- Original Message -----
From: "Axel Heitland" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, April 22, 2002 1:29 PM
Subject: Re: [DOTNET] Finding out the IP-Address of a PC


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.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to