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
最新推荐文章于 2024-03-07 09:36:09 发布