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

相关推荐
花酒锄作田5 小时前
使用 pkgutil 实现动态插件系统
python
前端付豪9 小时前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽10 小时前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战10 小时前
Pydantic配置管理最佳实践(一)
python
阿尔的代码屋16 小时前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent
人工智能·python
pe7er1 天前
macOS 应用无法打开(权限问题)解决方案
macos·mac
AI探索者1 天前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者1 天前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh1 天前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅1 天前
Python函数入门详解(定义+调用+参数)
python