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

相关推荐
一只鹿鹿鹿1 小时前
信息安全等级保护安全建设防护解决方案(总体资料)
运维·开发语言·数据库·面试·职场和发展
喵叔哟1 小时前
9. 【Blazor全栈开发实战指南】--Blazor调用JavaScript
开发语言·javascript·udp
wuqingshun3141591 小时前
如何停止一个正在退出的线程
java·开发语言·jvm
我命由我123451 小时前
Element Plus - Form 的 resetField 方法观察记录
开发语言·前端·javascript·vue.js·html·html5·js
朱包林2 小时前
Python基础
linux·开发语言·ide·python·visualstudio·github·visual studio
Eward-an2 小时前
【算法竞赛/大厂面试】盛最多水容器的最大面积解析
python·算法·leetcode·面试·职场和发展
no_work2 小时前
基于python预测含MLP决策树LGBM随机森林XGBoost等
python·决策树·随机森林·cnn
进击的雷神2 小时前
地址语义解析、多语言国家匹配、动态重试机制、混合内容提取——德国FAKUMA展爬虫四大技术难关攻克纪实
爬虫·python
FreakStudio2 小时前
一行命令搞定驱动安装!MicroPython 开发有了自己的 “PyPI”包管理平台!
python·stm32·单片机·嵌入式·arm·电子diy
Barkamin2 小时前
队列的实现(Java)
java·开发语言