#include <stdio.h>#include<winsock2.h>//This header file needs to be preceded by Windows.h#include <windows.h>#include<string>#include<iostream>#pragmaComment (lib, "Ws2_32.lib")using namespacestd;voidGetIP () {wsadata wsadata; //the WSADATA structure is used to store the Windows Sockets initialization information that is returned by calling the AfxSocketInit global function. if(WSAStartup (Makeword (2,0), &wsadata))//initializing the Windows Sockets API{printf ("WSAStartup failed%s\n", WSAGetLastError ()); Exit (-1);//Exception Exit } Charhostname[ the]; if(GetHostName (HostName,sizeof(HostName)))//Get host name{printf ("Error:%u\n", WSAGetLastError ()); Exit (-1);//Exception Exit} printf ("Host Name:%s\n", HostName); Hostent*host=gethostbyname (HostName);//gets host information based on host name. if(host==NULL) {printf ("Error:%u\n", WSAGetLastError ()); Exit (-1); } cout<<"host address Type:"<Endl<<"Address List:"<Endl<<"Alias list :"<Endl<<"Address Length:"<Endl<<"Official host Name:"<Endl; for(intI=0; host->h_addr_list[i]!=0; i++) {cout<<"the host IP"<<i+1<<": "<<inet_ntoa (* (structin_addr*) *host->h_addr_list) <<Endl; } cout<<"-----------------------------------------------"<<Endl; WSACleanup (); }voidGetsysinfo () {system_info sysInfo; //The structure contains information about the current computer: The architecture of the computer, the type of the central processing Unit, the number of central processors in the system, the size of the page, and other information. Osversioninfoex osvi; GetSystemInfo (&sysInfo); Osvi.dwosversioninfosize=sizeof(OSVI); if(GetVersionEx (LPOSVERSIONINFOW) &osvi)) {printf ("Operating system version:%u.%u.%u\n", osvi.dwMajorVersion, Osvi.dwminorversion,osvi.dwbuildnumber); printf ("Service Pack:%u.%u\n", Osvi.wservicepackmajor, Osvi.wservicepackminor); } printf ("processor architecture:%u\n", sysinfo.wprocessorarchitecture); printf ("processor level:%u\n", Sysinfo.wprocessorlevel); printf ("Processor version:%u\n", sysinfo.wprocessorrevision); printf ("Processor Mask:%u\n", Sysinfo.dwactiveprocessormask); printf ("number of processors:%u\n", sysinfo.dwnumberofprocessors); printf ("processor type:%u\n", Sysinfo.dwprocessortype); printf ("page Size:%u\n", sysinfo.dwpagesize); printf ("Application Minimum Address:%u\n", sysinfo.lpminimumapplicationaddress); printf ("Application Maximum address:%u\n", sysinfo.lpmaximumapplicationaddress); printf ("virtual memory allocation granularity:%u\n", sysinfo.dwallocationgranularity); printf ("OemId:%u\n", Sysinfo.dwoemid); printf ("wreserved:%u\n", sysinfo.wreserved);}intMain () {getip (); Getsysinfo (); return 0; }
Reference: https://blog.csdn.net/lynch0571
C + + Obtains system information (IP address, hardware information, etc.)