title: Getting the 'external' IP address in Java
body: <p>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.</p>
  
  <p>My following IPAddress class only gets the local IP address of the machine.</p>
  
  <pre><code>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;
      }
  }
  </code></pre>