c++得到本地用户名和IP
时间:2014-06-17 16:38:03
收藏:0
阅读:223
bool CDlgResetAlarmInfo::GetLocalUserNameAddIP(CString &a_lstrUserName ,CString &a_IpStr) { char buf[256]=""; WSADATA w; WSAStartup(0x0101, &w); struct hostent *ph = 0; gethostname(buf, 256); string hostNmae = buf; a_lstrUserName = hostNmae.c_str(); ph = gethostbyname(buf); const char *IP =inet_ntoa(*((struct in_addr *)ph->h_addr_list[0])); string strIp =IP; a_IpStr = strIp.c_str(); WSACleanup(); if (a_lstrUserName == "" || a_IpStr == "") { return false; } return true; }
评论(0)