Getting the 'external' IP address in Java

Posted by Caylem on Stack Overflow See other posts from Stack Overflow or by Caylem
Published on 2010-05-30T15:27:17Z Indexed on 2010/05/30 15:32 UTC
Read the original article Hit count: 216

Filed under:
|

Hi

I'm not too sure how to go about getting the external IP address of the machine as a computer outside of a network would see it. My following IPAddress class only gets the local IP address of the machine.

Any help would be appreciated.

Thanks.

public class IPAddress {

private InetAddress thisIp;

private String thisIpAddress;

private void setIpAdd(){

    try{
        InetAddress thisIp = InetAddress.getLocalHost();
        thisIpAddress = thisIp.getHostAddress().toString();
    }

    catch(Exception e){}

}

protected String getIpAddress(){
    setIpAdd();
    return thisIpAddress;
}

}

© Stack Overflow or respective owner

Related posts about java

Related posts about ipaddress