본문 바로가기
프로그래밍/java

자바로 MAC Address 알아오기

by Super User 2011. 1. 14.


import java.net.*;
public class NetworkTest {
    
    public static void main(String[] args) throws Exception  {
        
  InetAddress address = InetAddress.getLocalHost();

  NetworkInterface ni = NetworkInterface.getByInetAddress(address);

  byte[] mac = ni.getHardwareAddress();
  
  String macaddr = "";
  for (int i = 0; i < mac.length; i++) {
   macaddr += String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "");
  }
  System.out.println (macaddr);
    }
}

'프로그래밍 > java' 카테고리의 다른 글

자바 XML 만들기  (0) 2011.05.03
String.format에서 콤마(,) 찍기  (0) 2011.04.18
jxl 엑셀 수정 예제  (0) 2010.06.25
자바 날짜 조작  (0) 2010.05.31
자바 SimpleDateFormat 정리 - 시간 및 날짜(Date)  (0) 2010.05.31