Python-Mac格式转换脚本

2023-12-25 17:38:51

一、原因:

? ? ? ? 将c4:ef:da:12:5c:53 变为 c4ef-da12-5c53
二、代码

import re

mac_addresses = []

# Read the file
with open('client_list.txt', 'r') as file:
    # Read file contents into a list
    mac_addresses = [line.strip() for line in file]

# Process and print MAC addresses
for mac_address in mac_addresses:
    # Convert MAC address format from c4:ef:da:12:5c:53 to c4ef-da12-5c53
    mac = re.sub(r'[:]', '', mac_address)
    # Insert '-' every 4 characters
    mac = '-'.join(mac[i:i+4] for i in range(0, len(mac), 4))
    # Prepend 'sta ' to the MAC address
    mac = 'sta ' + mac
    print(mac)

三、需要在同一个目录下放置一个client_list.txt的文件放入你需要修改的mac地址清单

文章来源:https://blog.csdn.net/weixin_46510209/article/details/135204192
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。