js随机生成mac地址的代码

2023-10-21 11:05:54 浏览数 (1)

代码语言:javascript复制
console.log(make_mac().toUpperCase())

function make_mac(){
  var mac = make_mac_1();
  for(var i=0; i<4; i  ){
    mac = mac   ':'   make_mac_1();
  }
  return mac;
}
function make_mac_1(){
  var n=Math.round(Math.random()*255);
  var n_hex=n.toString(16);
  if( n_hex.length==1 ){
    n_hex = '0'   n_hex;
  }
  return n_hex;
}

运行结果:AB:BE:CA:33:AD

0 人点赞