turk_bayr.jpg (8863 bytes)

header.jpg (23201 bytes)

PROG
RAM

22 Haz 2001 GET HOSTNAME and IP ADDRESS of LOCAL COMPUTER

VC++ Articels


button_programming.jpg (4736 bytes)







This code will get the host name and ip for the computer on which the code is run. This works in Visual C++ 5 SP1/2 on NT4 and Windows 9X.
Requirements

#include <winsock.h>
Link with Wsock32.lib

That's It.

{
    WORD wVersionRequested;
    WSADATA wsaData;
    char name[255];
    CString ip;
    PHOSTENT hostinfo;
    wVersionRequested = MAKEWORD ( 2,0 );
    if ( WSAStartup ( wVersionRequested, &wsaData ) == 0)
    {
        if ( gethostname ( name, sizeof( name )) == 0)
       {
            if ((hostinfo = gethostbyname(name)) != NULL )
            {
                ip = inet_ntoa (*(struct in_addr*)*hostinfo->h_addr_list);
            }
        }
        WSACleanup();
    }

}

 

 

home | about me | links | projects | clean energy | programming

 

 

 

 

 

 

Hosted by www.Geocities.ws

1