?
It is very easy:
try {InetAddress localhost = InetAddress .getLocalHost (); LOG.info ("IP Addr:" + localhost.getHostAddress ()); // Just this host has many IP addresses .... InetAddress [] allMyIps = InetAddress.getAllByName (localhost.getCanonicalHostName ()); If (allMyIps! = Null & allMyIps.length & gt; 1) {LOG.info ("Full list of IP address:"); For (Int i = 0; I & lt; allMyIps.length; i ++) {LOG.info ("" + all MIIPs [I]); }}} Hold (unknownhostexception e) {LOG.info ("(error in retrieving server host name)"); } {LOG.info ("complete list of network interface"); (Counting & lt; network interface & gt; n = network interface.gateNetwork interface (); nbs earlames ();) {network interface intf = en.nextElement (); LOG.info ("+" intf.getName () + "" + intf.getDisplayName ()); For (Counting & lt; InetAddress & gt; enumIpAddr = intf.getInetAddresses (); enumIpAddr.hasMoreElements ();) {LOG.info ("+ + enumIpAddr.nextElement (.) ToString ()); }}} Hold (SocketException e) {LOG.info ("(error in retrieving network interface list)"); }
Comments
Post a Comment