1. 获得本机主机名
GetModuleFileName(NULL,info.InstallPath,128);//程序运行路径
GetUserName(user_name, &dwBufferLen);//用户名
gethostname(hostname, MAX_PATH);//主机名
GetComputerName(hostname, &dwBufferLen);//主机名
2.根据主机名获取IP
struct hostent FAR* lpHostEnt = gethostbyname(hostname);LPSTR lpAddr = lpHostEnt->h_addr_list[0];
// 将IP地址转化成字符串形式
struct in_addr inAddr;
memmove(&inAddr, lpAddr, 4);
char* m_strIP = inet_ntoa(inAddr)
3.根据IP获取MAC
HRESULT hResult;
IPAddr ipAddr;
ULONG pulMAC[2];
ULONG ulLen;
char strMacAddr[100] = { 0 };
ipAddr = inet_addr((char*)hostIP);
memset(pulMAC, 0, sizeof(pulMAC));
ulLen = 6;
hResult = SendARP(ipAddr, 0, pulMAC, &ulLen);
if (hResult = NO_ERROR)
{
printf("find nithing!\n");
return;
}
unsigned char * mac_addr = (unsigned char*)pulMAC;
sprintf_s(strMacAddr, "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x\n", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
memcpy_s(info.mac_addr, sizeof(info.mac_addr), strMacAddr, sizeof(info.mac_addr));
4.获取系统版本
OSVERSIONINFO osver = { sizeof(OSVERSIONINFO) };
GetVersionEx(&osver);