get Random Mac Address - Java Network

Java examples for Network:Mac Address

Description

get Random Mac Address

Demo Code


//package com.java2s;
import java.util.Random;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(getRandomMacAddress());
    }/*  w  w  w  .j  ava  2  s  .  c om*/

    public static String getRandomMacAddress() {
        String mac = "";
        Random r = new Random();
        for (int i = 0; i < 6; i++) {
            int n = r.nextInt(255);
            mac += String.format("%02x", n);
        }
        return mac.toUpperCase();
    }
}

Related Tutorials