■ 개발 정리/JAVA

로컬컴퓨터 MAC 주소 가져오기

파코키 2017. 8. 22. 12:59





로컬컴퓨터 MAC 주소 가져오기




// 로컬 IP취득

InetAddress ip = InetAddress.getLocalHost();

System.out.println("IP : " + ip.getHostAddress());

// 네트워크 인터페이스 취득

NetworkInterface netif = NetworkInterface.getByInetAddress(ip);


// 네트워크 인터페이스가 NULL이 아니면

if (netif != null) {

// 네트워크 인터페이스 표시명 출력

System.out.print(netif.getDisplayName() + " : ");

// 맥어드레스 취득

byte[] mac = netif.getHardwareAddress();

// 맥어드레스 출력

for (byte b : mac) {

System.out.printf("[%02X]", b);

}

System.out.println();

}