• c++得到本地username和IP


    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;
    }


  • 相关阅读:
    MUI-页面传参数
    Spring-boot:多模块打包
    PythonDay11
    PythonDay10
    PythonDay09
    PythonDay08
    PythonDay07
    PythonDay06
    PythonDay05
    PythonDay04
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10054136.html
Copyright © 2020-2023  润新知