吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 287|回复: 12
收起左侧

[经验求助] 【Python求助】急求可以随机改mac地址的Python脚本

[复制链接]
lammysoft 发表于 2024-5-2 21:03
200吾爱币
急求可以随机改自定义网卡的mac地址的python脚本,或者bat脚本也可以
下面的这个程序可以满足我的要求,但是希望他是python版本的脚本

网卡MAC自动修改工具_V1.0 - 『精品软件区』 - 吾爱破解 - LCG - LSG |安卓破解|病毒分析|[url]www.52pojie.cn[/url]

有没有前辈Python大佬来指导一下,萌新试了很久都不行

急求

最佳答案

查看完整内容

再试试这个,注意修改后需要重新启动网卡: https://blog.csdn.net/wx_lanyu/article/details/84455332

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

milaoshu1020 发表于 2024-5-2 21:03
再试试这个,注意修改后需要重新启动网卡:
https://blog.csdn.net/wx_lanyu/article/details/84455332
yucevip 发表于 2024-5-2 22:07
import os  
import random  
import re  
  
def generate_random_mac():  
    """  
    生成一个随机的MAC地址  
    """  
    hex_digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']  
    mac = ':'.join(''.join(random.choice(hex_digits) for _ in range(2)) for _ in range(6))  
    return mac.lower()  
  
def change_mac_address(interface, new_mac):  
    """  
    修改指定网络接口的MAC地址  
  
    参数:  
        interface (str): 网络接口名称,如'以太网'或'Wi-Fi'  
        new_mac (str): 新的MAC地址,格式为'xx:xx:xx:xx:xx:xx'  
  
    返回:  
        bool: 如果成功修改则返回True,否则返回False  
    """  
    # 尝试修改MAC地址  
    command = f'netsh interface set interface "{interface}" admin=disable'  
    os.system(command)  
  
    # 等待接口禁用完成(这里只是一个简单的等待,实际可能需要更复杂的逻辑)  
    # 注意:这不是一个可靠的等待方法,只是为了示例  
    os.system('timeout /t 5')  
  
    command = f'netsh interface set interface "{interface}" admin=enable mac={new_mac}'  
    result = os.system(command)  
  
    # 检查命令是否成功执行(os.system()的返回值是命令的退出码)  
    return result == 0  
  
def main():  
    # 获取所有网络接口的列表(这可能需要更复杂的逻辑来准确获取)  
    # 在这个例子中,我们假设用户会手动输入接口名称  
    interface = input("Enter the network interface name (e.g., Ethernet or Wi-Fi): ").strip()  
  
    # 生成随机的MAC地址  
    new_mac = generate_random_mac()  
    print(f"New MAC address: {new_mac}")  
  
    # 尝试修改MAC地址  
    if change_mac_address(interface, new_mac):  
        print(f"MAC address of {interface} changed successfully to {new_mac}.")  
    else:  
        print("Failed to change MAC address.")  
  
if __name__ == "__main__":  
    main()
 楼主| lammysoft 发表于 2024-5-2 22:57
yucevip 发表于 2024-5-2 22:07
import os  
import random  
import re  

好像不太行

[PowerShell] 纯文本查看 复制代码
Microsoft Windows [版本 10.0.18362.30]
(c) 2019 Microsoft Corporation。保留所有权利。

C:\Windows\system32>C:\Users\Lammy\Desktop\wifi
'C:\Users\Lammy\Desktop\wifi' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

C:\Windows\system32>cd C:\Users\Lammy\Desktop\wifi

C:\Users\Lammy\Desktop\wifi>python Mac.py
Enter the network interface name (e.g., Ethernet or Wi-Fi): WLAN
New MAC address: 8f:5f:50:c5:7a:7e


等待 0 秒,按一个键继续 ...
'mac' 不是这个指令的有效参数。
此命令提供的语法不正确。请查看帮助以获取正确的语法信息。

用法 set interface [name = ] IfName
            [ [admin = ] ENABLED|DISABLED
              [connect = ] CONNECTED|DISCONNECTED
              [newname = ] NewName ]

      设置接口参数。

      IfName  - 接口名称
      admin   - 接口是否被启用
      connect - 是否连接接口 (仅用于非 LAN)。
      newname - 接口的新名称 (仅用于非 LAN)。

      注意:
      - 除名称外,还必须至少指定一个选项。
      - 如果 connect = CONNECTED 被指定,那么接口被自动
        启用,甚至在 admin = DISABLED 选项被指定时也是如
        此。

示例:

      set interface name="有线以太网连接" admin=DISABLED
      set interface name="有线以太网连接" newname="连接 1"


MAC address of WLAN changed successfully to 8f:5f:50:c5:7a:7e.

C:\Users\Lammy\Desktop\wifi>ipconfig /all

Windows IP 配置

   主机名  . . . . . . . . . . . . . : DESKTOP-CS9RQ4V
   主 DNS 后缀 . . . . . . . . . . . :
   节点类型  . . . . . . . . . . . . : 混合
   IP 路由已启用 . . . . . . . . . . : 否
   WINS 代{过}{滤}理已启用 . . . . . . . . . : 否

C:\Users\Lammy\Desktop\wifi>ipconfig /all

Windows IP 配置

   主机名  . . . . . . . . . . . . . : DESKTOP-CS9RQ4V
   主 DNS 后缀 . . . . . . . . . . . :
   节点类型  . . . . . . . . . . . . : 混合
   IP 路由已启用 . . . . . . . . . . : 否
   WINS 代{过}{滤}理已启用 . . . . . . . . . : 否

无线局域网适配器 本地连接* 8:

   媒体状态  . . . . . . . . . . . . : 媒体已断开连接
   连接特定的 DNS 后缀 . . . . . . . :
   描述. . . . . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter
   物理地址. . . . . . . . . . . . . : A6-62-29-23-B0-4B
   DHCP 已启用 . . . . . . . . . . . : 是
   自动配置已启用. . . . . . . . . . : 是

无线局域网适配器 WLAN:

   媒体状态  . . . . . . . . . . . . : 媒体已断开连接
   连接特定的 DNS 后缀 . . . . . . . :
   描述. . . . . . . . . . . . . . . : Intel(R) Wi-Fi 6 AX201 160MHz
   物理地址. . . . . . . . . . . . . : A6-62-29-23-B0-4A
   DHCP 已启用 . . . . . . . . . . . : 是
   自动配置已启用. . . . . . . . . . : 是

C:\Users\Lammy\Desktop\wifi>
milaoshu1020 发表于 2024-5-3 10:04
改注册表就行了:

How Does It Work?
This software just writes a value into the windows registry. When the Network Adapter Device is enabled, windows searches for the registry value 'NetworkAddress' in the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1- 08002bE10318}\[ID of NIC e.g. 0001]. If a value is present, windows will use it as MAC address, if not, windows will use the hard coded manufacturer provided MAC address. Some Network Adapter drivers have this facility built-in. It can be found in the Advance settings tab in the Network Adapter's Device properties in Windows Device Manager.
surepj 发表于 2024-5-3 10:06
我也不会,以下来自gpt的回复,试试看

在Windows系统上更改MAC地址可以使用类似的方法,但是需要使用不同的命令。Windows上更改MAC地址可以通过netsh命令来实现。下面是一个在Windows系统上更改MAC地址的示例代码:

import subprocess

def change_mac(interface, new_mac):
    print("Changing MAC address for", interface, "to", new_mac)
    subprocess.call(["netsh", "interface", "set", "interface", interface, "admin=DISABLED"])
    subprocess.call(["netsh", "interface", "set", "interface", interface, "address", new_mac])
    subprocess.call(["netsh", "interface", "set", "interface", interface, "admin=ENABLED"])

# 在这里替换成你想要更改的接口和新的MAC地址
interface = "Wi-Fi"
new_mac = "00-11-22-33-44-55"

change_mac(interface, new_mac)

请注意,接口的名称可能因系统而异,例如在不同的Windows版本或不同的网络设备上。确保你使用的接口名称是正确的,以及新MAC地址是有效的。

bootice 发表于 2024-5-3 10:12
[Asm] 纯文本查看 复制代码
import random
import subprocess
import os

def generate_random_mac():
    # 生成随机MAC地址,注意避免使用FF:FF:FF:FF:FF:FF和00:00:00:00:00:00
    mac = [random.randint(0x00, 0xFF) for _ in range(6)]
    while mac == [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] or mac == [0x00, 0x00, 0x00, 0x00, 0x00, 0x00]:
        mac = [random.randint(0x00, 0xFF) for _ in range(6)]
    return ':'.join(['{:02X}'.format(x) for x in mac])

def set_mac_address(interface_name, mac_address):
    # 使用netsh命令更改MAC地址
    command = f"netsh interface set address {interface_name} source=static addr={mac_address}"
    subprocess.run(command, shell=True, check=True)

def main():
    # 生成随机MAC地址
    random_mac = generate_random_mac()
    print(f"Generated MAC address: {random_mac}")
    
    # 获取网络接口名称,这里假设更改的是你想要更改的第一个网络接口
    # 如果需要更改特定的接口,可以手动指定接口名称
    interface_name = "无线网络连接"  # 请根据实际情况修改为正确的接口名称
    
    # 应用MAC地址
    set_mac_address(interface_name, random_mac)
    print(f"MAC address has been set to {random_mac} on interface {interface_name}")

if __name__ == "__main__":
    if os.name == "nt":  # 确保脚本在Windows系统上运行
        main()
    else:
        print("This script is intended to be run on Windows systems only.")
milaoshu1020 发表于 2024-5-3 10:14
用python改一下注册表就可以了:
https://www.bilibili.com/read/cv6202948/
 楼主| lammysoft 发表于 2024-5-3 10:37
surepj 发表于 2024-5-3 10:06
我也不会,以下来自gpt的回复,试试看

[md]在Windows系统上更改MAC地址可以使用类似的方法,但是需要使 ...

这个interface是什么参数,

输出:
Changing MAC address for WLAN to 00-11-22-33-44-55

address 不是 admin 的可接受值。
参数错误。
 楼主| lammysoft 发表于 2024-5-3 10:41
bootice 发表于 2024-5-3 10:12
[mw_shl_code=asm,true]import random
import subprocess
import os

Generated MAC address: 05-71-70-8C-C1-70
找不到下列命令: interface set address WLAN source=static addr=05-71-70-8C-C1-70。
Traceback (most recent call last):
  File "C:\Users\Lammy\Desktop\wifi\Mac.py", line 32, in <module>
    main()
  File "C:\Users\Lammy\Desktop\wifi\Mac.py", line 27, in main
    set_mac_address(interface_name, random_mac)
  File "C:\Users\Lammy\Desktop\wifi\Mac.py", line 15, in set_mac_address
    subprocess.run(command, shell=True, check=True)
  File "D:\Lib\subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'netsh interface set address WLAN source=static addr=05-71-70-8C-C1-70' returned non-zero exit status 1.
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-18 06:39

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表