How can I get the real local host IP address in an applet?

John Zukowski

Applet security restrictions do not let you get this in an untrusted applet via InetAddress.getLocalHost().

However, you can get this address by creating a Socket connection back to the web server from which you came and asking the Socket for the local address:

    URL url = getDocumentBase();
    String host = url.getHost();
    Socket socket = new Socket(host, 80);
    InetAddress addr = socket.getLocalAddress();
    String hostAddr = addr.getHostAddress();
    System.out.println("Addr: " + hostAddr);
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact