본문 바로가기

java

로컬 서버 네트워크 정보

try {
   InetAddress localhost = InetAddress.getLocalHost();
   log.info(" IP Addr: " + localhost.getHostAddress());
   // Just in case this host has multiple IP addresses....
   InetAddress[] allMyIps = InetAddress.getAllByName(localhost.getCanonicalHostName());
      if (allMyIps != null && allMyIps.length > 1) {
         log.info(" Full list of IP addresses:");
         for (int i = 0; i < allMyIps.length; i++) {
            log.info("    " + allMyIps[i]);
      }
   }
} catch (UnknownHostException e) {
   log.info(" (error retrieving server host name)");
}
try {
   log.info("Full list of Network Interfaces:");
   for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
      NetworkInterface intf = en.nextElement();
      log.info("    " + intf.getName() + " " + intf.getDisplayName());
      for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
         log.info("        " + enumIpAddr.nextElement().toString());
      }
   }
} catch (SocketException e) {
   log.info(" (error retrieving network interface list)");
}

'java' 카테고리의 다른 글

싱글톤 클래스 생성 팁  (0) 2017.06.15
http <-> https 세션 공유  (0) 2014.04.01
피보나치 수열 간단 알고리즘  (0) 2013.09.26
java 엑셀 함수 NPV 구현  (0) 2013.07.09
java 엑셀 함수 IRR 구현  (0) 2013.07.09