mac address
package egovframework.kr.co.fw.util;
import java.net.InetAddress;
import java.net.NetworkInterface;
public class NetUtil {
public static void main(String[] args) {
try {
InetAddress addr = InetAddress.getLocalHost();
NetworkInterface ni = NetworkInterface.getByInetAddress(addr);
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);
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.net.InetAddress;
import java.net.NetworkInterface;
public class MacAddressTest {
public static void main(String[] args){
try{
InetAddress addr = InetAddress.getLocalHost();
/* IP 주소 가져오기 */
String ipAddr = addr.getHostAddress();
System.out.println("***********************" + ipAddr);
/* 호스트명 가져오기 */
String hostname = addr.getHostName();
System.out.println("%%%%%%%%%%%%%%" + hostname);
/* NetworkInterface를 이용하여 현재 로컬 서버에 대한 하드웨어 어드레스를 가져오기 */
NetworkInterface ni = NetworkInterface.getByInetAddress(addr);
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);
} catch (Exception e) {
e.printStackTrace();
}
}
}
'JAVA' 카테고리의 다른 글
method 동적 호출 (0) | 2019.02.27 |
---|---|
MD5 암호화 예제 (0) | 2019.02.27 |
Listener :: ServletContextListener (0) | 2019.02.15 |
List 정렬 (0) | 2019.02.15 |
[JAVA]JUnit 테스트 코드 (0) | 2017.11.30 |