Python-Mac格式转换脚本

一、原因:

将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地址清单

相关推荐
2301_78731243几秒前
MySQL版本迁移中如何处理全局变量_手动比对新旧配置文件
jvm·数据库·python
AKA__Zas2 分钟前
初识多线程(初初识)
java·服务器·开发语言·学习方法
LiAo_1996_Y3 分钟前
JavaScript中利用宏任务拆分阻塞任务的实操案例
jvm·数据库·python
qq_349317485 分钟前
如何在 Go 中安全高效地将 SSH 公钥复制到远程服务器
jvm·数据库·python
zhangrelay7 分钟前
三分钟云课实践速通--概率统计--python版
linux·开发语言·笔记·python·学习·ubuntu
龙腾AI白云9 分钟前
大模型部署资源不足?轻量化部署解决方案
python·数据挖掘
一晌小贪欢11 分钟前
《Python办公Excel处理》第二节:精通openpyxl,让Excel排版与读写自动化
python·自动化·excel
我不是立达刘宁宇11 分钟前
CORS(跨原产资源共享)靶场1
python·http
Xidaoapi13 分钟前
Python调用OpenAI API完整教程:从零到精通
python
张赐荣13 分钟前
深入详解在 Python 中用 ctypes 调用 Windows API 清空回收站
开发语言·windows·python