C/C++获取操作系统、CPU、内存信息、硬盘、IP和MAC、进程信息(windows和linux)

C++跨平台获取计算机硬件与网络信息:从原理到实战 在系统编程与运维工具开发中,获取底层硬件与网络信息是构建监控、诊断、适配等高级功能的基础。其核心原理在于操作系统通过特定的API或文件系统接口(如Windows的WMI、Linux的/proc与/sysfs)向应用程序暴露系统状态。掌握这些接口的调用方法,对于开发高性能、高可靠性的系统级软件具有重要技术价值,广泛应用于系统监控工具、软件许可验证、网络配置调试等场景。本文聚焦于C++语言,深入剖析了在Windows和Linux两大主流平台上,如何通过条件编译、抽象接口等策略,高效、准确地获取CPU、内存、磁盘 阅读详情
AI摘要

本文介绍了一种在Windows和Linux环境下获取系统信息的方法,包括操作系统版本、CPU型号频率、内存大小、硬盘序列号、网络信息等内容。

有时候需要在工程里面获取一些系统或者硬件的信息,比如系统版本,cpu,内存,显卡,硬盘,网络等,作为后续软件功能判断的依据,甚至参与性能算法自适应建模

Windows

操作系统和内存信息在windows下通过系统的API来获取,CPU信息则需要需要通过底层CPUID指令取得

代码:

#include <iostream> 
#include <string>
#include <string.h>
#include <winsock2.h> // include must before window.h
#include <iphlpapi.h>
#include <windows.h>  

#pragma comment(lib, "iphlpapi.lib")

#pragma warning(disable: 4996) // avoid GetVersionEx to be warned

// ***** global macros ***** //
static const int kMaxInfoBuffer = 256;
#define  GBYTES  1073741824  
#define  MBYTES  1048576  
#define  KBYTES  1024  
#define  DKBYTES 1024.0  

// ---- get os info ---- //
void getOsInfo()
{
	// get os name according to version number
	OSVERSIONINFO osver = { sizeof(OSVERSIONINFO) };
	GetVersionEx(&osver);
	std::string os_name;
	if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 0)
		os_name = "Windows 2000";
	else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 1)
		os_name = "Windows XP";
	else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 0)
		os_name = "Windows 2003";
	else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 2)
		os_name = "windows vista";
	else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 1)
		os_name = "windows 7";
	else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 2)
		os_name = "windows 10";

	std::cout << "os name: " << os_name << std::endl;
	std::cout << "os version: " << osver.dwMajorVersion << '.' << osver.dwMinorVersion << std::endl;

}

// ---- get cpu info ---- //

#ifdef _WIN64

// method 2: usde winapi, works for x86 and x64
#include <intrin.h>
void getCpuInfo()
{
	int cpuInfo[4] = {-1};
	char cpu_manufacture[32] = { 0 };
	char cpu_type[32] = { 0 };
	char cpu_freq[32] = { 0 };

	__cpuid(cpuInfo, 0x80000002);
	memcpy(cpu_manufacture, cpuInfo, sizeof(cpuInfo));

	__cpuid(cpuInfo, 0x80000003);
	memcpy(cpu_type, cpuInfo, sizeof(cpuInfo));

	__cpuid(cpuInfo, 0x80000004);
	memcpy(cpu_freq, cpuInfo, sizeof(cpuInfo));

	std::cout << "CPU manufacture: " << cpu_manufacture << std::endl;
	std::cout << "CPU type: " << cpu_type << std::endl;
	std::cout << "CPU main frequency: " << cpu_freq << std::endl;
}

#else

// mothed 1: this kind asm embedded in code only works in x86 build
// save 4 register variables
DWORD deax;
DWORD debx;
DWORD decx;
DWORD dedx;

// init cpu in assembly language
void initCpu(DWORD veax)
{
	__asm
	{
		mov eax, veax
		cpuid
			mov deax, eax
			mov debx, ebx
			mov decx, ecx
			mov dedx, edx
	}
}

long getCpuFreq()
{
	int start, over;
	_asm
	{
		RDTSC
		mov start, eax
	}
	Sleep(50);
	_asm
	{
		RDTSC
		mov over, eax
	}
	return (over - start) / 50000;
}

std::string getManufactureID()
{
	char manuID[25];
	memset(manuID, 0, sizeof(manuID));

	initCpu(0);
	memcpy(manuID + 0, &debx, 4); // copy to array
	memcpy(manuID + 4, &dedx, 4);
	memcpy(manuID + 8, &decx, 4);

	return manuID;
}

std::string getCpuType()
{
	const DWORD id = 0x80000002; // start 0x80000002 end to 0x80000004
	char cpuType[49];
	memset(cpuType, 0, sizeof(cpuType));

	for (DWORD t = 0; t < 3; t++)
	{
		initCpu(id + t);

		memcpy(cpuType + 16 * t + 0, &deax, 4);
		memcpy(cpuType + 16 * t + 4, &debx, 4);
		memcpy(cpuType + 16 * t + 8, &decx, 4);
		memcpy(cpuType + 16 * t + 12, &dedx, 4);
	}

	return cpuType;
}

void getCpuInfo()
{
	std::cout << "CPU manufacture: " << getManufactureID() << std::endl;
	std::cout << "CPU type: " << getCpuType() << std::endl;
	std::cout << "CPU main frequency: " << getCpuFreq() << "MHz" << std::endl;
}

#endif

// ---- get memory info ---- //
void getMemoryInfo()
{
	std::string memory_info;
	MEMORYSTATUSEX statusex;
	statusex.dwLength = sizeof(statusex);
	if (GlobalMemoryStatusEx(&statusex))
	{
		unsigned long long total = 0, remain_total = 0, avl = 0, remain_avl = 0;
		double decimal_total = 0, decimal_avl = 0;
		remain_total = statusex.ullTotalPhys % GBYTES;
		total = statusex.ullTotalPhys / GBYTES;
		avl = statusex.ullAvailPhys / GBYTES;
		remain_avl = statusex.ullAvailPhys % GBYTES;
		if (remain_total > 0)
			decimal_total = (remain_total / MBYTES) / DKBYTES;
		if (remain_avl > 0)
			decimal_avl = (remain_avl / MBYTES) / DKBYTES;

		decimal_total += (double)total;
		decimal_avl += (double)avl;
		char  buffer[kMaxInfoBuffer];
		sprintf_s(buffer, kMaxInfoBuffer, "total %.2f GB (%.2f GB available)", decimal_total, decimal_avl);
		memory_info.append(buffer);
	}
	std::cout << memory_info << std::endl;
}

// ---- get harddisk info ---- //
std::string execCmd(const char *cmd)
{
	char buffer[128] = { 0 };
	std::string result;
	FILE *pipe = _popen(cmd, "r");
	if (!pipe) throw std::runtime_error("_popen() failed!");
	while (!feof(pipe))
	{
		if (fgets(buffer, 128, pipe) != NULL)
			result += buffer;
	}
	_pclose(pipe);

	return result;
}

void getHardDiskInfo()
{
	std::string hd_seiral = execCmd("wmic path win32_physicalmedia get SerialNumber");
	std::cout << "HardDisk Serial Number: " << hd_seiral << std::endl;
}

// ---- get network info ---- //
void getNetworkInfo()
{
	// PIP_ADAPTER_INFO struct contains network information
	PIP_ADAPTER_INFO pIpAdapterInfo = new IP_ADAPTER_INFO();
	unsigned long adapter_size = sizeof(IP_ADAPTER_INFO);
	int ret = GetAdaptersInfo(pIpAdapterInfo, &adapter_size);

	if (ret == ERROR_BUFFER_OVERFLOW)
	{
		// overflow, use the output size to recreate the handler
		delete pIpAdapterInfo;
		pIpAdapterInfo = (PIP_ADAPTER_INFO)new BYTE[adapter_size];
		ret = GetAdaptersInfo(pIpAdapterInfo, &adapter_size);
	}

	if (ret == ERROR_SUCCESS)
	{
		int card_index = 0;

		// may have many cards, it saved in linklist
		while (pIpAdapterInfo)
		{
			std::cout << "---- " << "NetworkCard " << ++card_index << " ----" << std::endl;

			std::cout << "Network Card Name: " << pIpAdapterInfo->AdapterName << std::endl;
			std::cout << "Network Card Description: " << pIpAdapterInfo->Description << std::endl;

			// get IP, one card may have many IPs
			PIP_ADDR_STRING pIpAddr = &(pIpAdapterInfo->IpAddressList);
			while (pIpAddr)
			{
				char local_ip[128] = { 0 };
				strcpy(local_ip, pIpAddr->IpAddress.String);
				std::cout << "Local IP: " << local_ip << std::endl;

				pIpAddr = pIpAddr->Next;
			}

			char local_mac[128] = { 0 };
			int char_index = 0;
			for (int i = 0; i < pIpAdapterInfo->AddressLength; i++)
			{
				char temp_str[10] = { 0 };
				sprintf(temp_str, "%02X-", pIpAdapterInfo->Address[i]); // X for uppercase, x for lowercase
				strcpy(local_mac + char_index, temp_str);
				char_index += 3;
			}
			local_mac[17] = '\0'; // remove tail '-'

			std::cout << "Local Mac: " << local_mac << std::endl;

			// here just need the first card info
			break;
			// iterate next
			//pIpAdapterInfo = pIpAdapterInfo->Next;
		}
	}

	if (pIpAdapterInfo)
		delete pIpAdapterInfo;
}

// ---- get process info ---- //
void getProcessInfo()
{
    int pid = GetCurrentProcessId();
    // TODO: cpu and mem usage
    printf("Current Pid: %d\n", pid);
}

int main(int argc, char *argv[])
{
	std::cout << "=== os information ===" << std::endl;
	getOsInfo();

	std::cout << "=== cpu infomation ===" << std::endl;
	getCpuInfo();

	std::cout << "=== memory information ===" << std::endl;
	getMemoryInfo();

	std::cout << "=== harddisk information ===" << std::endl;
	getHardDiskInfo();

	std::cout << "=== network information ===" << std::endl;
	getNetworkInfo();

        printf("=== process information ===\n");
        getProcessInfo();

	return 0;
}

 

结果:

===os information===
os name: windows 10
os version: 6.2
===cpu infomation===
CPU main frequency: 2612MHz
CPU manufacture: GenuineIntel
CPU type:        Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz
===memory information===
total 7.86 GB (1.38 GB available)
=== harddisk information ===
HardDisk Serial Number: SerialNumber
0520B6776730A1F4
=== network information ===
---- NetworkCard 1 ----
Network Card Name: {403C08C9-5600-4BE9-8021-AAAADB63D678}
Network Card Description: Intel(R) Ethernet Connection (5) I219-LM
Local IP: 10.12.0.142
Local Mac: 50-9A-4C-14-B5-7F
=== process information ===
Current Pid: 2367

 

Linux
linux下很多信息都是存放着系统的/proc目录下,因此读文件就可以获取到了

代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// mostly need to read the linux config files to get system info

// ---- get os info ---- //
void getOsInfo()
{
    FILE *fp = fopen("/proc/version", "r");
    if(NULL == fp)
        printf("failed to open version\n");
    char szTest[1000] = {0};
    while(!feof(fp))
    {
        memset(szTest, 0, sizeof(szTest));
        fgets(szTest, sizeof(szTest) - 1, fp); // leave out \n
        printf("%s", szTest);
    }
    fclose(fp);
}

// ---- get cpu info ---- //
void getCpuInfo()
{
    FILE *fp = fopen("/proc/cpuinfo", "r");
    if(NULL == fp)
        printf("failed to open cpuinfo\n");
    char szTest[1000] = {0};
    // read file line by line
    while(!feof(fp))
    {
        memset(szTest, 0, sizeof(szTest));
        fgets(szTest, sizeof(szTest) - 1, fp); // leave out \n
        printf("%s", szTest);
    }
    fclose(fp);
}


// ---- get memory info ---- //
void getMemoryInfo()
{
    FILE *fp = fopen("/proc/meminfo", "r");
    if(NULL == fp)
        printf("failed to open meminfo\n");
    char szTest[1000] = {0};
    while(!feof(fp))
    {
        memset(szTest, 0, sizeof(szTest));
        fgets(szTest, sizeof(szTest) - 1, fp);
        printf("%s", szTest);
    }
    fclose(fp);
}

// ---- get harddisk info ---- //
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/hdreg.h>

void getHardDiskInfo()
{
    // use cmd, this is the only way
    static struct hd_driveid hd;
    int fd;

    if ((fd = open("/dev/sda", O_RDONLY | O_NONBLOCK)) < 0)
    {
        printf("ERROR opening /dev/sda\n");
        return;
    }

    if (!ioctl(fd, HDIO_GET_IDENTITY, &hd))
    {
        printf("model ", hd.model);
        printf("HardDisk Serial Number: %.20s\n", hd.serial_no);
    }
    else
        printf("no available harddisk info");
}

// ---- get network info ---- //
#include <unistd.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <ifaddrs.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <linux/if.h>
void getNetworkInfo()
{
    // get hostname and external ip, simple and best way
    char host_name[256] = {0};
    gethostname(host_name, sizeof(host_name));

    struct hostent* host = gethostbyname(host_name);
    char ip_str[32] = {0};
    const char* ret = inet_ntop(host->h_addrtype, host->h_addr_list[0], ip_str, sizeof(ip_str));
    if (ret != NULL)
    {
        printf("Current HostName: %s\n", host_name);
        printf("Current external IP: %s\n", ip_str);
    }

    // get multiple ip, works for linux
    struct ifaddrs *ifAddrStruct = NULL;
    struct ifaddrs *ifa = NULL;

    getifaddrs(&ifAddrStruct);

    for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next)
    {
        if (!ifa->ifa_addr)
            continue;

        // check if IP4
        if (ifa->ifa_addr->sa_family == AF_INET)
        {
            void *tmpAddrPtr = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
            char local_ip[INET_ADDRSTRLEN];
            inet_ntop(AF_INET, tmpAddrPtr, local_ip, INET_ADDRSTRLEN);

            // actually only need external ip
            printf("%s IP: %s\n", ifa->ifa_name, local_ip);
        }
    }

    if (ifAddrStruct)
        freeifaddrs(ifAddrStruct);


    // get mac, need to create socket first, may not work for mac os
    struct ifreq ifr;
    int fd = socket(AF_INET, SOCK_DGRAM, 0);

    char local_mac[128] = { 0 };

    strcpy(ifr.ifr_name, "eth0"); // only need ethernet card
    if (0 == ioctl(fd, SIOCGIFHWADDR, &ifr))
    {
        char temp_str[10] = { 0 };
        memcpy(temp_str, ifr.ifr_hwaddr.sa_data, 6);
        sprintf(local_mac, "%02x-%02x-%02x-%02x-%02x-%02x", temp_str[0]&0xff, temp_str[1]&0xff, temp_str[2]&0xff, temp_str[3]&0xff, temp_str[4]&0xff, temp_str[5]&0xff);
    }

    printf("Local Mac: %s\n", local_mac);

}

// ---- get process info ---- //
void getProcessInfo()
{
    int pid = getpid();
    // TODO: cpu and mem usage
    printf("Current Pid: %d\n", pid);
}

int main(int argc, char **argv)
{
    printf("=== os information ===\n");
    getOsInfo();

    printf("=== cpu infomation ===\n");
    getCpuInfo();

    printf("=== memory information ===\n");
    getMemoryInfo();

    printf("=== harddisk information ===\n");
    getHardDiskInfo();

    printf("=== network information ===\n");
    getNetworkInfo();

    printf("=== process information ===\n");
    getProcessInfo();

    return 0;
}

 

结果:

===os information===
Linux version 4.8.6-300.fc25.x86_64 (mockbuild@bkernel02.phx2.fedoraproject.org) (gcc version 6.2.1 20160916 (Red Hat 6.2.1-2) (GCC) ) #1 SMP Tue Nov 1 12:36:38 UTC 2016
===cpu infomation===
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 58
model name	: Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz
stepping	: 9
microcode	: 0x1b
cpu MHz		: 2599.755
cache size	: 3072 KB
===memory information===
MemTotal:        3061552 kB
MemFree:           89584 kB
MemAvailable:     596876 kB
Buffers:           70372 kB
Cached:           707548 kB
SwapCached:          392 kB
=== harddisk information ===
HardDisk Serial Number: 0520B6776730A1F4
=== network information ===
Current HostName: tashaxing
Current external IP: 192.168.136.140
lo IP: 127.0.0.1
eth0 IP: 192.168.136.140
Local Mac: 00-0c-29-ec-7a-80
=== process information ===
Current Pid: 1152

 

PS:显卡参数可以用制造商提供的驱动API来取得

 

 

 


 

 

 

 

c++ linux获取硬件的信息 此外,为了运行这些代码,需要以root用户身份运行程序或者在程序中使用sudo命令。物理磁盘的性能指标:IO延迟、读IO/s、写IO/s、读KB/s、写KB/s、读error/s、写error/s。如果想使用C++来获取硬件信息,可以使用系统调用来获取硬件信息。物理磁盘的字典信息: 磁盘编号、型号、固件版本、容量、序列号、缓存、转速(仅限机械磁盘)函数调用该命令,并解析命令输出来获取所需的信息。在Linux下,可以使用一些命令行工具来获取硬件信息,如。这些工具可以列出包括磁盘在内的系统硬件的详细信息。 阅读详情

相关推荐

利用C/C++实现硬盘和CPU温度获取的详尽指南

通过本文的详细介绍,我们深入了解了如何使用C/C++实现计算机硬盘和CPU的实时温度获取。从硬盘温度获取的基础知识、S.M.A.R.T.技术的应用,到CPU温度获取的系统API调用和跨平台实现,我们全面解析了温度获取的实现过程,并通过丰富的示例代码展示了具体的实现细节。在实际项目中,温度监控是保障系统稳定性和性能的重要环节。掌握了温度获取的方法后,您将能够在系统监控、硬件检测、性能优化等领域大展身手,为您的项目提供强有力的技术支持。

m0_57781768的博客 2005

获取硬盘物理序列号、型号等参数

该软件主要为一动态链结库文件: DiskSerial.DLL,它能获取物理硬盘的型号(Model Number)、物理序列号(Serial Number)、修订号(Revision Number)、缓存容量(Buffer Size)、柱面数(Cylinders)、磁头数(Heads)、每磁道的扇区数(Sectors per track)。<;br>; 在WINDOWS NT 4.0和WINDOWS 2000操作环境下能获取IDE硬盘和SCSI硬盘的以上参数;在WINDOWS 9X和WINDOWS ME操作环境下能获取IDE硬盘的以上参数。<;br>; 本库文件供VC、BCB、VB、VFP、PB和DEPHI开发人员使用,其它开发环境下未经测试,欢迎大家测试。在以上开发环境下分别提供以下文件:<;br>; DiskSerial.H,DiskSerial.Lib 两个文件提供给C/C++ 程序员调用;<;br>; DiskSerial.pas 文件提供给Dephi程序员调用;<;br>; DiskSerial.bas 文件提供给VB程序员调用。<;br>; 调用格式请进入以下链接获取例子程序(http://vip.6to23.com/songdai/)。若在使用过程中发现任何问题或有新的想法请及时与我联系。<;br>; 以上参数都是硬盘生产厂商所提供,不会随硬盘的分区、格式化而变化。<;br>; 注册用户将获得免费升级及更新 E-MAIL 通知。<;br>; E-Mail:songdai@163.net

C语言获取硬件信息:CPU序列号、硬盘序列号、MAC地址与网线状态实战

在设备管理与安全审计场景中,硬件信息采集是构建设备指纹的基础。Windows平台下,CPU标识并非简单序列号,而需通过CPUID指令组合厂商、型号与步进信息;硬盘序列号需区分物理盘与卷序列号,常借助DeviceIoControl发送IOCTL_STORAGE_QUERY_PROPERTY获取;网卡IP、MAC与网线状态则依赖GetAdaptersAddresses枚举适配器并解析OperStatus。理解这些底层原理,有助于开发装机登记、远程运维及授权校验工具。从C语言工程视角,剖析这三类信息的采集方法、常

weixin_30342363的博客 291

用驱动获取cpu的温度

用驱动获取cpu的温度,针对intel的cpu

C语言跨平台获取硬件信息实战:CPU序列号、硬盘序列号与MAC地址采集

在设备授权、资产盘点等场景中,常需获取CPU序列号、硬盘序列号等硬件信息来生成设备唯一标识。C语言作为底层系统语言,既可通过CPUID指令、DeviceIoControl等Windows系统API读取,也能依托sysfs、ioctl等Linux内核接口实现跨平台采集。理解这些系统级读取原理,是构建稳定设备指纹的关键。该方案不依赖第三方库,直接调用操作系统原生能力,适用于机器绑定、网络诊断、机房巡检等工程实践。本文以一份可编译的C工程为例,梳理双平台硬件信息获取的完整实现路径与关键避坑点,为开发者提供可直接落

weixin_29194817的博客 333

C语言跨平台硬件信息采集:CPU序列号、硬盘序列号与MAC地址

硬件信息采集是系统运维、软件授权绑定和设备指纹识别的基础能力。在Windows和Linux环境下,CPU序列号、硬盘序列号、网卡MAC地址及链路状态的读取机制差异显著,开发者常需针对不同平台维护多套代码。通过C语言封装统一的数据结构,可以将平台差异收敛在底层实现中,向上层提供一致的硬件信息接口。这类技术广泛应用于资产盘点、授权验证、运维监控等场景,关键在于理解各平台的设备抽象和系统调用原理。本文基于一套完整的C语言源码包,深入解析跨平台获取CPU序列号、硬盘序列号、MAC地址与网线插入检测的实现思路,并分享

weixin_31534091的博客 223

linux系统编程 获取系统信息

存放用户账户信息的文件,就是口令文件。

qq_29750559的博客 556

C语言跨平台获取CPU序列号、硬盘序列号与网卡MAC实战

在软件授权、资产盘点和远程运维等场景中,获取CPU序列号、硬盘序列号与网卡MAC地址是构建设备指纹的基础能力。C语言作为系统级编程语言,天然适合直接调用操作系统底层接口,但Windows与Linux的硬件信息访问机制差异巨大:Windows依赖WMI服务、DeviceIoControl和GetAdaptersAddresses,Linux则更多通过sysfs虚拟文件系统与ioctl系统调用完成读取。理解这些接口的原理与权限边界,能帮助开发者避开OEM默认值污染、NVMe协议不兼容、字节序错乱等典型陷阱。无论

weixin_29164843的博客 340

c++ 代码获取CPU温度

import psutil def get_cpu_temperature(): temperature = psutil.sensors_temperatures()['cpu-thermal'][0].current return temperature print(get_cpu_temperature())

weixin_35757191的博客 1668

C语言跨平台获取硬件信息:CPU序列号、硬盘序列号、网卡MAC与插线状态实战

在系统编程与设备管理领域,采集硬件标识信息是软件授权绑定、资产登记与网络巡检的基础能力。不同操作系统提供的接口差异显著,Windows下常依赖WMI与IP Helper,而Linux则多采用sysfs与ioctl组合。本文从底层原理出发,梳理CPU序列号、硬盘序列号、网卡MAC地址及链路状态的获取机制,重点对比WMI、IOCTL、getifaddrs等典型技术方案,并剖析虚拟机干扰、权限不足、序列号读空等高频故障的根因与应对策略。无论是构建跨平台部署的巡检工具,还是设计基于硬件指纹的授权系统,均可参考文中多

weixin_29169505的博客 357

用C语言跨平台采集硬件信息:CPU、硬盘、网卡与网线状态全搞定

硬件信息采集是系统编程与设备身份识别的基础环节,涉及CPU序列号、硬盘序列号、网卡MAC地址等关键标识的获取。在跨平台开发场景中,Linux与Windows的API机制差异显著:Linux下可通过/proc/cpuinfo、sysfs及udevadm读取底层数据,Windows则依赖WMI查询与GetAdaptersAddresses接口。这些原理决定了技术选型与容错策略,尤其需要对权限不足、WMI首次调用延迟、序列号语义混淆等工程陷阱做充分规避。硬件信息获取能力支撑着软件授权绑定、资产管理、网络诊断等典型

weixin_29192365的博客 278

windows linux C/C++获取操作系统、CPU、内存信息、硬盘、IP和MAC

Windows 操作系统和内存信息在windows下通过系统的API来获取,CPU信息则需要需要通过底层CPUID指令取得 代码: #include <iostream> #include <string> #include <string.h> #include <winsock2.h> // include must before wi...

whatday的专栏 2216

C语言跨平台获取硬件信息:CPU、硬盘、网卡与网线状态实战

在系统工具、设备绑定授权和资产管理等工程场景中,获取CPU序列号、硬盘序列号、网卡MAC地址乃至网线插拔状态,是开发者常遇到的刚性需求。然而Windows与Linux的底层接口差异巨大,Windows依赖WMI、注册表与IOCTL,Linux则基于sysfs、ioctl与Netlink,直接调用往往需要反复查阅文档并处理各类平台兼容问题。本文从硬件信息采集的基本原理出发,拆解两种操作系统下的核心API差异与实现路径,详细说明CPU标识、物理硬盘序列号、网卡IP/MAC以及链路状态的可靠获取方法,并给出跨平台

weixin_34194829的博客 312

C/C++获取操作系统、CPU、内存信息、硬盘、IP和MAC(windows和linux)

https://blog.csdn.net/u012234115/article/details/71056957

Ryan 2287

跨平台硬件指纹采集:C语言直读CPU/硬盘/网卡实现

硬件指纹是设备唯一性识别的核心技术,其本质是通过底层系统接口获取不可轻易篡改的物理标识。原理上需绕过shell命令依赖,直接访问内核暴露的稳定节点(如Linux /sys/block/xxx/serial、/proc/cpuinfo,Windows WMI与DeviceIoControl),以规避容器环境缺失工具、发行版裁剪、权限策略拦截等常见失效场景。该技术具备高稳定性与低侵入性,显著提升软件授权、资产盘点和国产化适配中的设备绑定可靠性。典型应用涵盖工业控制软件、嵌入式设备管理及信创环境下的License

weixin_42623010的博客 272

C语言跨平台获取真实硬件指纹:CPU/硬盘/网卡序列号与链路状态

硬件指纹是软件授权、设备绑定和合规审计的基础技术概念,其核心原理在于绕过用户态缓存,通过内核级接口(如Linux的ioctl SG_IO、Windows的IOCTL_STORAGE_QUERY_PROPERTY)直接访问固件或寄存器层数据。该技术具备强权限校验、抗虚拟化伪造、支持物理设备甄别等工程价值,广泛应用于工业控制、金融终端、嵌入式激活等对设备唯一性要求严苛的场景。本文聚焦于C语言原生实现,覆盖硬盘真实序列号提取、物理网卡MAC与链路状态原子性获取、以及跨平台统一抽象设计,特别解决消费级CPU序列号普

weixin_29189003的博客 199
上一篇: python脚本编程:批量对比文本文件,根据具体字段比较差异
下一篇: Qt工程pro文件的简单配置(尤其是第三方头文件和库)
踏莎行hyx
博客等级 码龄13年 1554粉丝 165原创
评论 12
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值