Java for循环生成MAC地址
尝试使用以下命令创建 MAC 地址值循环:
String macAddr = "AA:BB:CC:DD:";
char[] chars = {'A', 'B', 'C', 'D', 'E', 'F'};
String[] strings = {"0", "0", "0", "0"};
for (int i=0; i<strings.length; i++)
{
//counter from 0 to F
for (int d = 0; d <= 9; d++)
{
strings[i] = ""+d;
print();
}
for (int d = 0; d< chars.length; d++)
{
strings[i] = ""+chars[d];
print();
}
}
其中 print() 是:
System.out.println(macAddr+strings[3]+strings[2]+":"+strings[1]+strings[0]);
但我遇到了问题:
AA:BB:CC:DD:00:0D
AA:BB:CC:DD:00:0E
AA:BB:CC:DD:00:0F
AA:BB:CC:DD:00:0F
AA:BB:CC:DD:00:1F
AA:BB:CC:DD:00:2F
AA:BB:CC:DD:00:3F
这两个问题是每次交叉处的对偶值(例如 AA:BB:CC:DD:00:0F) 以及每个值上停止于 F 的值。
我试图将它们设置为:
AA:BB:CC:DD:00:0D
AA:BB:CC:DD:00:0E
AA:BB:CC:DD:00:0F
AA:BB:CC:DD:00:11
AA:BB:CC:DD:00:12
AA:BB:CC:DD:00:13
等等
干杯:)
Trying to make a loop of MAC address values with:
String macAddr = "AA:BB:CC:DD:";
char[] chars = {'A', 'B', 'C', 'D', 'E', 'F'};
String[] strings = {"0", "0", "0", "0"};
for (int i=0; i<strings.length; i++)
{
//counter from 0 to F
for (int d = 0; d <= 9; d++)
{
strings[i] = ""+d;
print();
}
for (int d = 0; d< chars.length; d++)
{
strings[i] = ""+chars[d];
print();
}
}
where print() is:
System.out.println(macAddr+strings[3]+strings[2]+":"+strings[1]+strings[0]);
But i'm getting run-over:
AA:BB:CC:DD:00:0D
AA:BB:CC:DD:00:0E
AA:BB:CC:DD:00:0F
AA:BB:CC:DD:00:0F
AA:BB:CC:DD:00:1F
AA:BB:CC:DD:00:2F
AA:BB:CC:DD:00:3F
The two problems are the dual values at each crossover (e.g. AA:BB:CC:DD:00:0F)
and the values stopping at F on each value.
I'm trying to get them as:
AA:BB:CC:DD:00:0D
AA:BB:CC:DD:00:0E
AA:BB:CC:DD:00:0F
AA:BB:CC:DD:00:11
AA:BB:CC:DD:00:12
AA:BB:CC:DD:00:13
etc.
Cheers :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
long
存储您的 Mac 地址并创建一个小函数将其转换为String
。输出示例:
Use a
long
to store your mac address and create a small function to convert it to aString
.Example output:
尝试这个以保持简单:
输出(缩写):
Try this for keeping it simple:
Output (abbreviated):