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

相关推荐
Albert Edison1 小时前
【Python】学生管理系统
开发语言·数据库·python
love530love3 小时前
【ComfyUI】解决 ModuleNotFoundError: No module named ‘inference_core_nodes‘ 问题
人工智能·windows·python·comfyui·inference-core
宇木灵4 小时前
C语言基础-十、文件操作
c语言·开发语言·学习
云泽8084 小时前
C++ 多态入门:虚函数、重写、虚析构及 override/final 实战指南(附腾讯面试题)
开发语言·c++
亚亚的学习和分享5 小时前
python基础语法----条件语句
python
yanghuashuiyue5 小时前
lambda+sealed+record
java·开发语言
Zzz 小生6 小时前
LangChain Streaming-Overview:流式处理使用完全指南
人工智能·python·语言模型·langchain·github
yzx9910136 小时前
Python数据结构入门指南:从基础到实践
开发语言·数据结构·python
百锦再6 小时前
Jenkins 全面精通指南:从入门到脚本大师
运维·后端·python·servlet·django·flask·jenkins
衍生星球6 小时前
【JSP程序设计】Servlet对象 — page对象
java·开发语言·servlet·jsp·jsp程序设计