본문 바로가기

# IT, Computer Science/MFC, API

내 컴퓨터의 아이피주소를 얻는 함수

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

 

CString GetMyIP()

{

                  CString ipAddr;

 

 

                  WSADATA wsaData;

                  WORD wVersionRequested = MAKEWORD( 2, 0 );

 

 

                  if( WSAStartup( wVersionRequested, &wsaData ) == 0 )

                  {

                                   char name[256];

 

 

                                   if( gethostname( name, sizeof( name ) ) == 0 )

                                   {

                                                     PHOSTENT hostinfo = gethostbyname( name );

 

 

                                                     if( hostinfo != NULL)

                                                     {

                                                                       ipAddr = inet_ntoa( *( struct in_addr* ) *hostinfo->h_addr_list );

                                                     }

                                   }

 

 

                                   WSACleanup();

                  }

 

 

                  return ipAddr;

}





출처 : http://a.tk.co.kr/335