bash - 在bash中生成一定范围内的mac地址
问题描述
我需要一些帮助来生成 bash 脚本中某个范围内的所有 mac 地址。
#!/bin/bash
mac='00:00:00:00'
index=16000
start_index=53
for i in $( eval echo {$start_index..$((start_index+index))})
do
bridge fdb add printf "$mac:%x\n" $i dev sw1p1 static master
done
设法在python中这样做
mac = '00:00:00:00'
index = 16000
start_index = 53
for number in range(start_index, start_index + index):
hex_num = hex(number)[2:].rjust(4, '0')
entry = "{}:{}{}:{}{}".format(mac, *hex_num)
os.system(f"bridge fdb add {entry} dev sw1p1 static master)
解决方案
使用算术扩展将数字拆分为两个八位位组,并使用printf
.
# define mac, start_index, index here
# assume index <= 65535
for ((num=start_index; num<=index; num++)); do
printf -v sfx ':%02X:%02X' $((num>>8)) $((num&255))
bridge fdb add "${mac}${sfx}" dev sw1p1 static master
done
推荐阅读
- javascript - Javascript 中的 getMonth() 格式为 dd/mm/yyyy
- python-3.x - 详细参数在 PMML 管道中不起作用
- .net - dotnet dev-certs https --trust not work 并返回此错误“创建 HTTPS 开发人员证书时出错。”
- react-native - react-native-modal 内的导航
- python-3.x - Keras 方法 'predict' 和 'predict_generator' 结果不同
- autohotkey - 循环中的pixelgetcolor有问题,愿意接受任何建议
- node.js - 带有 ts 和 vs 代码的 nodemon 使用 --inspect 附加调试连接超时
- java - ActiveMQ:如何避免将调试消息发送到 log4j 控制台?
- c# - 在模型 .net 核心 Web api 中返回带有 null 必需属性的 BadRequest
- asp.net-core - 如何使用 Blazor 语法折叠/展开 Razor 组件?