随机生成 imsi imei mac

本文介绍了一种生成虚拟IMEI、IMSI和MAC地址的方法,通过随机数和特定算法确保了地址的有效性和唯一性。适用于测试场景中模拟设备的身份标识。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://blog.youkuaiyun.com/argonwu/article/details/42971909




private static String getIMEI() {// calculator IMEI

int r1 = 1000000 + new java.util.Random().nextInt(9000000);
int r2 = 1000000 + new java.util.Random().nextInt(9000000);
String input = r1 + "" + r2;
char[] ch = input.toCharArray();
int a = 0, b = 0;
for (int i = 0; i < ch.length; i++) {
int tt = Integer.parseInt(ch[i] + "");
if (i % 2 == 0) {
a = a + tt;
} else {
int temp = tt * 2;
b = b + temp / 10 + temp % 10;
}
}
int last = (a + b) % 10;
if (last == 0) {
last = 0;
} else {
last = 10 - last;
}
return input + last;
}


private static String getImsi() {
// 460022535025034
String title = "4600";
int second = 0;
do {
second = new java.util.Random().nextInt(8);
} while (second == 4);
int r1 = 10000 + new java.util.Random().nextInt(90000);
int r2 = 10000 + new java.util.Random().nextInt(90000);
return title + "" + second + "" + r1 + "" + r2;
}
private static String getMac(){
char[] char1 = "abcdef".toCharArray();
char[] char2 = "0123456789".toCharArray();
StringBuffer mBuffer = new StringBuffer();
for (int i = 0; i < 6; i++) {
int t = new java.util.Random().nextInt(char1.length);
int y = new java.util.Random().nextInt(char2.length);
int key = new java.util.Random().nextInt(2);
if (key ==0) {
mBuffer.append(char2[y]).append(char1[t]);
}else {
mBuffer.append(char1[t]).append(char2[y]);
}

if (i!=5) {
mBuffer.append(":");
}
}
return mBuffer.toString();
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值