이글루스 로그인


Java SE 6.0 에서 네크워크 카드의 MAC address 가져오기

 

package test;

import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;


public class NetworkInterfaceTest {
    public static void main(String[] args) throws SocketException {
        Enumeration<NetworkInterface> nienum = NetworkInterface.getNetworkInterfaces();
        while (nienum.hasMoreElements()) {
            NetworkInterface ni = nienum.nextElement();
            System.out.print(ni.getName());
            System.out.print(" : ");
            byte[] hardwareAddress = ni.getHardwareAddress();
            String div = "";
            if (hardwareAddress != null) {
                for (byte b : hardwareAddress) {
                    System.out.print(div);
                    System.out.format("%02X", b);
                    div = "-";
                }
            }
            System.out.println();
        }
    }
}

위와 같이 가져올 수 있다.
Java SE 6.0 부터 제공하는 getHardwareAddress() 를 사용하면 되며, 내부적으로는 JNI 로 구현되어있다.

by sayjava | 2008/07/11 10:59 | Programmer's notes | 트랙백 | 덧글(3)

트랙백 주소 : http://sayjava.egloos.com/tb/4480789
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
Commented by benelog at 2008/07/11 15:08
오호. 재밌는 정보네요~ 감사합니다.
Commented by javatuning at 2008/07/29 11:03
번역 빨리 하시오~~~

메일 보내도 안보길래

블로그로 갈구겠소~~~~
Commented by 박성민 at 2009/03/16 00:17
받아오는 주소를 String 으로 형변환해서 비교할때 쓰고 싶은데 형변환 하는 방법은 없나요??

:         :

:

비공개 덧글


◀ 이전 페이지          다음 페이지 ▶