windows 平台c++代码获取物理地址

这篇博客详细介绍了在Windows环境下,使用C++编程如何获取计算机的物理地址。通过引用头文件IPApi.h和实现源文件IPApi.cpp,开发者可以学习到具体的实现步骤和关键代码片段。
摘要由CSDN通过智能技术生成

头文件IPApi.h

#pragma once

// Returns number of NICs
// 'address' contains the physical address of index='idx'
int get_physical_address(char * address, int idx);

// Returns number of NICs
// 'address' contains the physical address of index=0
int get_first_physical_address(char * address);

bool is_physical_address(const char * address);

源文件IPApi.cpp

#include "IPApi.h"
#include <winsock2.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <stdlib.h>

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

#define WORKING_BUFFER_SIZE 15000

#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))

static void phy_adapter_address2str(PIP_ADAPTER_ADDRESSES paddress, char * saddress) {
    int j = 0;
    for (int i = 0; i < (int)paddress->PhysicalAddressLength; i++) {
        j += sprintf(saddress + j, &#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值