Here you can find the source of getCustomMACFormat(NetworkInterface inte)
Parameter | Description |
---|---|
inte | NetworkInterface to retrieve MAC address. |
Parameter | Description |
---|---|
SocketException | if is not possible to retries MAC address as byte. |
IllegalArgumentException | if argument is null. |
public static String getCustomMACFormat(NetworkInterface inte) throws SocketException, IllegalArgumentException
//package com.java2s; //License from project: Open Source License import java.net.NetworkInterface; import java.net.SocketException; public class Main { /**//from w w w . ja v a 2 s.c o m * This method returns the MAC address of Network Interface. * @param inte {@link NetworkInterface} to retrieve MAC address. * @return {@link String} of formatted MAC address. * @throws SocketException if is not possible to retries MAC address as byte. * @throws IllegalArgumentException if argument is null. */ public static String getCustomMACFormat(NetworkInterface inte) throws SocketException, IllegalArgumentException { if (inte == null) throw new IllegalArgumentException("Network Interface can not be null."); byte[] mac = inte.getHardwareAddress(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < mac.length; i++) sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? ":" : "")); return sb.toString(); } }