Quantcast
Channel: VMware Communities : All Content - VMware® ThinApp®
Viewing all articles
Browse latest Browse all 1382

Get the correct local IP address from java applet

$
0
0

Hello all, I have Problem go through it!

 

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...).

 

Here is my test :

 

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();   }   }

The result is :

 

  HostName = xxxx    HostAddressLocal = xx.xx.xx.xx    hostAddress = 10.10.11.51    hostAddress = 192.168.23.1    hostAddress = 192.168.106.1

 

where xx.xx.xx.xx isn't the correct address. The correct is 10.10.11.51.

 

EDIT in response to jarnbjo :

 

Your Crystal Report 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 :

 

Socket s = new Socket("www.w3c.org", 80);    InetAddress ip = s.getLocalAddress();    System.out.println("Internet IP = " + ip.toString());    s.close();

 

I have this result :

    >> Internet IP = /127.0.0.1

And not 10.10.11.51

 

Thanks

Nicolewells


Viewing all articles
Browse latest Browse all 1382

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>