生成一段号段的mac

JAEE框架

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigInteger;

public class test {
// A4:DE:C9:01:FB:D0 :A4:DE:C9:02:1E:F7
public static void main(String[] args) {
// 生成文件名
String filePath = “mac.txt”;
File file = new File(filePath);
if (file.exists()) {
file.delete();
}
// 设定起始地址, 以及数量
printMac(filePath, “A4:DE:C9:01:FB:D0”, 9000);
}

private static void printMac(String filePath, String start, int count) {
    start = start.replaceAll(":", "");
    try {
        File file = new File(filePath);
        FileWriter writer = new FileWriter(file, true);
        BigInteger num = new BigInteger(start, 16);
        BigInteger addNum = new BigInteger("1");
        String result = "";
        for (int i = 0; i < count; i++) {
            result = num.toString(16).toUpperCase();
            for (int j = 12 - result.length(); j > 0; j--) {
                result = "0" + result;
            }
            writer.write("INSERT INTO `t_device`(`id`, `other_id`, `mac`, `imei`, `component_version`, `framework_version`, `ip`, `client_version`, `vendor`, `model`, `v_id`, `m_id`, `device_type`, `create_time`, `last_update_time`, `status`, `root`, `manual_add`) VALUES (``, ``,`"+getMacAdr(result)+"` ``, ``, ``, ``, ``, `SZJY`, `model`, `361`, `m_id`, `0`, `2017-12-21 17:53:53`, `2017-12-21 17:53:53`, `1`, `0`, `1`)" + "\n");

            num = num.add(addNum);
        }
        writer.close();
        System.out.println("finished");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

private static String getMacAdr(String str) {
    StringBuilder result = new StringBuilder("");
    for (int i = 1; i <= 12; i++) {
        result.append(str.charAt(i - 1));
        if (i % 2 == 0) {
            result.append(":");
        }
    }
    return result.substring(0, 17);
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值