Skip to content

Instantly share code, notes, and snippets.

@Beasta
Last active September 29, 2023 06:41
Show Gist options
  • Save Beasta/34f28ff2ba0c9d07d9277ab6de2d5ae1 to your computer and use it in GitHub Desktop.
Save Beasta/34f28ff2ba0c9d07d9277ab6de2d5ae1 to your computer and use it in GitHub Desktop.
convert baicells IMSI to Mac
// starting number is the first IMSI number on the sim card package of 10
// function will create and return two arrays - first array is the 10 sequential IMSIs, second array is the 10 MACs
// it will also print a nice table for you
// you can run it in the browser console
// just copy past and then call it like this
// createArrays(xxxxxIMSIxxxxx)
function createArrays(startingNumber) {
// Generate first array
let array1 = [];
for(let i = 0; i < 10; i++) {
array1.push(startingNumber + i);
}
// Function that converts numbers to MAC-address like format
function IMSItoMAC(number) {
var strnum = number.toString();
if (!strnum || strnum.length !== 15) return null;
var last12 = strnum.substr(strnum.length - 12);
var result;
if (strnum[3] === '0') {
result = '8A0' + Number(last12).toString(16).toUpperCase();
} else {
result = '8A' + Number(last12).toString(16).toUpperCase();
}
return result.match(/.{2}/g).join(':');
}
// Generate second array based on the first one by transforming numbers to MAC-address like format
let array2 = [];
for(let i = 0; i < array1.length; i++) {
let result = IMSItoMAC(array1[i]);
if(result !== null) array2.push(result);
}
// Create a data object
let data = array1.map((e, i) => ({ 'IMSI': e, 'MAC': array2[i] }));
console.table(data);
// Return both arrays
return [array1, array2];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment