参考链接
- 3种方法来在Windows中变更电脑的Mac地址
https://zh.wikihow.com/在Windows中变更电脑的Mac地址 - Registry Functions - Windows applications | Microsoft Docs
https://docs.microsoft.com/zh-cn/windows/win32/sysinfo/registry-functions
代码
#include <windows.h>
#include <stdio.h>
#include <string.h>
void showErrorText(DWORD error_num);
int main()
{
HKEY hKey;
DWORD result;
char sname[13];
//打开注册表
result = RegOpenKeyEx(
HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4d36e972-e325-11ce-bfc1-08002be10318}\\0003",
0, // 保留参数必须填 0
KEY_WRITE, // 打开权限,写入
&hKey // 打开之后的句柄
);
if (result == ERROR_SUCCESS)
{
printf("open success!\n");
}
else
{
printf("open failed!\n");
showErrorText(result);
exit(-1);
}
//输入新的mac地址
while(strlen(sname) !=12)
{
memset(sname,0,sizeof(sname));
printf("please input a new mac address:");
scanf("%12s",sname) ;
}
// 设置 NetworkAddress
result = RegSetValueEx(
hKey,
"NetworkAddress", // Name字段
0, // 保留参数必须填 0
REG_SZ, // 键值类型为字符串
(const unsigned char *)sname, // 字符串首地址
strlen(sname) // 字符串长度
);
if (result == ERROR_SUCCESS)
{
printf("set success!\n");
}
else
{
printf("set failed!\n");
showErrorText(result);
exit(-2);
}
//关闭注册表
RegCloseKey(hKey);
// 重启网卡
printf("禁用网卡\n");
system("netsh interface set interface \"WLAN\" disabled");
printf("启用网卡\n");
system("netsh interface set interface \"WLAN\" enabled");
//暂停
system("pause");
return 0;
}
/*
* 根据错误码输出错误信息
*/
void showErrorText(DWORD error_num)
{
char *msg = NULL;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
error_num,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // 使用默认语言
(LPSTR)&msg,
0,
NULL
);
printf("Error code %d: \n", error_num);
if (msg == NULL)
{
printf("%s\n", "Unknown error");
}
else
{
printf("%s\n", msg);
}
system("pause");
}
注意
不同的电脑的wlan的注册表地址可能不一样,最后一项可能不是0003,可能是别的数字
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class{4d36e972-e325-11ce-bfc1-08002be10318}\0003
也可以用regedit直接更改注册表
不同的网卡,在禁用、启用网卡的时候输入不同的命令,
也可以在 控制面板→网络和共享中心→更改适配器设置 里面禁用、启用网卡。
运行步骤
先看一下参考链接里的第一条。
程序运行需要管理员权限
如果没用管理员权限运行就会:

管理员权限运行方法:
- 右键→以管理员身份运行
- 右键→属性→兼容性→以管理员身份运行此程序
- 在程序名中加入setup,比如将程序重命名为change_mac_setup.exe
确认输入格式正确的MAC地址。某些适配器(尤其是某些无线网卡)的MAC地址中第一个八位字节的第二个字符如果是2、6、A、E或以0开头,那么这些地址可能无法被更改。
重启网卡

绕过2、6、A、E的限制
使用winXP或Linux虚拟机
本文介绍了如何在Windows系统中通过注册表改变WLAN的Mac地址,包括参考链接、具体代码、操作注意事项及运行步骤。需要注意不同电脑的注册表路径可能不同,并提醒了关于2、6、A、E限制的解决办法,以及管理员权限运行和重启网卡的重要性。

3148

被折叠的 条评论
为什么被折叠?



