try {
   Enumeration<NetworkInterface> e= NetworkInterface.getNetworkInterfaces();
            while(e.hasMoreElements())
            {
                NetworkInterface n = e.nextElement();
                Enumeration<InetAddress> ee = n.getInetAddresses();
               
                while(ee.hasMoreElements())
                {
                    InetAddress i= (InetAddress) ee.nextElement();
                    String ip = i.getHostAddress().toString();
                   
                    StringTokenizer str = new StringTokenizer(ip, ".");
                    if(str.countTokens() == 4){
                     if(!ip.equals("127.0.0.1")){
                      System.out.println(ip);
                     }
                    }
                }
            }
  }
  catch (Exception e) {
   e.printStackTrace();
  }

+ Recent posts