title: Get the correct local IP address from java applet
body: <p>I would like to determine the local IP address from my java applet. The problem is when there are several IP adresses on the same machine, which has LAN and internet connections
  (palm, VMWare...). </p>
  
  <p>Here is my test :</p>
  
  <pre><code>    public static void main(String[] args) {
        try {
          String hostName = InetAddress.getLocalHost().getHostName();
          System.out.println("HostName = " + hostName);
          System.out.println("HostAddressLocal = " +
            InetAddress.getLocalHost().getHostAddress());
          InetAddress[] inetAddresses = InetAddress.getAllByName(hostName);
          for (InetAddress inetAddress : inetAddresses) {
            System.out.println("hostAddress = " + inetAddress.getHostAddress());
          }
        } catch (Exception e) {
            e.printStackTrace();
        }
      }
  </code></pre>
  
  <p>The result is :</p>
  
  <pre><code>    HostName = xxxx
      HostAddressLocal = xx.xx.xx.xx
      hostAddress = 10.10.11.51
      hostAddress = 192.168.23.1
      hostAddress = 192.168.106.1
  </code></pre>
  
  <p>where xx.xx.xx.xx isn't the correct address. The correct is 10.10.11.51.</p>
  
  <hr>
  
  <p>EDIT in response to <a href="https://stackoverflow.com/questions/1510526/get-the-correct-local-ip-adress-from-java-applet/1510642#1510642">jarnbjo</a> :</p>
  
  <p>Your crystal ball say the truth. You've understand my problem. The client can connect through a proxy so I can not use your first point. If I execute this code below on my computer : </p>
  
  <pre><code>    Socket s = new Socket("www.w3c.org", 80); 
      InetAddress ip = s.getLocalAddress(); 
      System.out.println("Internet IP = " + ip.toString()); 
      s.close(); 
  </code></pre>
  
  <p>I have this result : </p>
  
  <pre><code>    Internet IP = /127.0.0.1 
  </code></pre>
  
  <p>And not 10.10.11.51</p>