라이선스 적용을 위해 랜카드 정보를 찾는데 기존 방식은
Runtime.getRuntime().exec(“ipconfig /all”);
을 사용하여 InputStream 으로 추출 했습니다. 이렇게 하는 방법 외에 다른 방법을 해보니 예전에 특정아이피로 바인딩 하는 방법에서 찾을 수 있을 것 같아. 아래와 같이 해봤습니다.
간단하게 맥어드레스와 이름 만 출력 합니다.
// 설치된 모든 랜카드 정보를 얻는다. Enumeration netEnumeration = NetworkInterface.getNetworkInterfaces(); while (netEnumeration.hasMoreElements()) { // 랜카드 목록에서 랜카드 하나의 정보를 추출한다. NetworkInterface networkInterface = (NetworkInterface) netEnumeration.nextElement(); // 맥어드레스를 추출 byte[] data = networkInterface.getHardwareAddress(); if(data == null || data.length != 6) { continue; } StringBuilder macAddress = new StringBuilder(); // 맥어드레스를 읽기 쉬운 타입 => 00:00:00:00:00:00 형식으로 변환한다. for (int i = 0; i < data.length; i++) { macAddress.append(Integer.toHexString(0x10000 | (0xff & (int)data[ 0 + i])).substring(3, 5).toUpperCase()) if (i != 5) macAddress.append(":"); } // 출력한다. System.out.println("NAME:" + networkInterface.getDisplayName()); System.out.println("MAC: " + macAddress.toString()); }