C + + Obtains system information (IP address, hardware information, etc.)

Source: Internet
Author: User

#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.)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.