獲取計算機的名稱和IP地址

 

獲取計算機的名稱和IP地址

char szHostName[128];
 char szT[20];
 
 if( gethostname(szHostName, 128) == 0 )
 {
          // Get host adresses
          m_HostName.SetWindowText(szHostName);
         struct hostent * pHost; 
           int i;  
          pHost = gethostbyname(szHostName);
          for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )  
         {
                  char str[100];   
                 char addr[20];
                 int j;    
                 LPCSTR psz=inet_ntoa (*(struct in_addr *)pHost->h_addr_list[i]);
               m_IPAddr.AddString(psz);
        }

 } 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章