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;
}
c++得到本地用户名和IP,布布扣,bubuko.com
c++得到本地用户名和IP