惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 赵青青

AI模型Claude的Haiku、Sonnet、Opus 怎么选? obsidian(md笔记管理)使用实践 python中可变参数与装饰器的例子 C++ lambda 表达式 3ds max的obj文件格式说明 CPython调试和性能分析 Python3类型安全type hint Python3虚拟机和对象 vs编译cpp时设置排除项 Python311新特性-特化指令specializing adaptive interpreter-typing-asyncio 最小体积拉取git仓库并保持可更新 unity .net8 suppot comming pycharm一些减少代码warning的拼写检查设置 JavaScript速查表 Python cheatsheet 速查表 DirectX9(D3D9)游戏开发:高光时刻录制和共享纹理的踩坑 FFmpeg在游戏视频录制中的应用:画质与文件大小的综合比较 c++中字符串之string和char IMGUI快速入门
与ChatGPT的对话在windows上获取mac地址
赵青青 · 2024-11-03 · via 博客园 - 赵青青

碰到编程问题可以问chatgpt,他给的结果也很容易验证是否正确,跑一下代码正确与否一目了然,比如我想获取mac地址

c++中调用winapi实现

问:使用c++调用winapi获取电脑的mac地址

chatgpt:在C++中,你可以使用Windows API的 GetAdaptersInfo 函数来获取电脑的MAC地址。以下是一个示例:

#include <iostream>
#include <windows.h>
#include <iphlpapi.h>
#include <iomanip>

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

int main() {
    IP_ADAPTER_INFO AdapterInfo[16];
    DWORD dwBufLen = sizeof(AdapterInfo);

    DWORD dwStatus = GetAdaptersInfo(AdapterInfo, &dwBufLen);
    if (dwStatus != ERROR_SUCCESS) {
        std::cerr << "GetAdaptersInfo failed with error: " << dwStatus << std::endl;
        return 1;
    }

    PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;
    do {
        std::cout << "Adapter name: " << pAdapterInfo->AdapterName << std::endl;
        std::cout << "Adapter desc: " << pAdapterInfo->Description << std::endl;
        std::cout << "Adapter MAC: ";
        for (UINT i = 0; i < pAdapterInfo->AddressLength; i++) {
            if (i == (pAdapterInfo->AddressLength - 1))
                std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)pAdapterInfo->Address[i];
            else
                std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)pAdapterInfo->Address[i] << "-";
        }
        std::cout << std::endl;
        pAdapterInfo = pAdapterInfo->Next;
    } while(pAdapterInfo);

    return 0;
}

python中获取mac

问:使用python2获取电脑的mac地址

chatgpt:

在Python 2中,你可以使用内置的uuid模块来获取电脑的MAC地址。以下是一个示例:

import uuid

def get_mac_address():
    mac = uuid.getnode()
    return ':'.join(('%012X' % mac)[i:i+2] for i in range(0, 12, 2))

print(get_mac_address())

这段代码首先调用uuid.getnode()函数获取电脑的MAC地址,然后将其转换为常见的冒号分隔的格式。

需要注意的是,uuid.getnode()函数返回的是一个整数,所以我们需要使用字符串格式化将其转换为16进制的形式,并添加冒号。

我电脑上的网卡

比如我的电脑上有三个网卡

  1. Realtek PCIe 2.5GbE Family Controller
  2. ZTN Adapter V1
  3. TAP-Windows Adapter V9

image-20240721173620458

Realtek公司生产的一种网络接口控制器(NIC),也就是我们通常所说的网卡。这种网卡使用PCI Express(PCIe)接口连接到计算机,支持2.5Gbps的以太网连接。

零信任网络 (ZTN),IT安装的

Tap-Windows 适配器 V9 是一个虚拟网络接口。它提供了各种 VPN 客户端所需的功能,以促进 VPN 连接

虚拟网卡和物理网卡

虚拟网卡和非虚拟网卡的主要区别在于它们的实现方式和使用场景。

非虚拟网卡,也就是物理网卡,是一种硬件设备,它直接连接到计算机的主板上。物理网卡负责处理所有的网络通信,包括数据的发送和接收。例如,当你使用网线或Wi-Fi上网时,你的计算机就是通过物理网卡来连接到网络的。

虚拟网卡,顾名思义,是一种虚拟的网络接口,它是通过软件在操作系统中创建的。虚拟网卡可以模拟物理网卡的功能,但是它并不需要物理设备。虚拟网卡通常用于网络虚拟化,例如在虚拟机或容器中创建独立的网络环境,或者在VPN(虚拟专用网络)中创建安全的网络连接。

虚拟网卡和物理网卡的另一个区别是,虚拟网卡的MAC地址通常是随机生成的,而物理网卡的MAC地址是由制造商在生产时分配的,每个物理网卡的MAC地址都是唯一的。

总的来说,虚拟网卡和物理网卡都是网络接口,它们都可以用于网络通信,但是它们的实现方式和使用场景有所不同。