title: Getting IP address of client
body: <p>I am developing a web application using <em>JSP</em>, <em>Servlets</em> (Container: <em>Glassfish</em>) in which I need to get clients <code>IP Address</code>.</p>
  
  <p>I am getting the clients IP address, because I want to give access to some pages (like Customer maintenance forms) only on computers withing the office, I want to restrict access to those pages outside office.</p>
  
  <p>Following is my code so far:</p>
  
  <h2>way1</h2>
  
  <pre><code>String ipAddress =  request.getRemoteAddr();
  System.out.println("IP Address: "+ipAddress);
  </code></pre>
  
  <h2>way2</h2>
  
  <pre><code>String ipAddress=null;
  String getWay = request.getHeader("VIA");   // Gateway
  ipAddress = request.getHeader("X-FORWARDED-FOR");   // proxy
  if(ipAddress==null)
  {
      ipAddress = request.getRemoteAddr();
  }
  System.out.println("IP Address: "+ipAddress);
  </code></pre>
  
  <p>Above code gives me <code>different IP Address</code> each time when I restart my computer (Shutdown->Start or Restart).</p>
  
  <p>I am getting <code>IP6</code> like:</p>
  
  <pre><code>fe80:0:0:0:20ca:1776:f5ff:ff15%13
  </code></pre>
  
  <p>Let me know what is wrong with this code?</p>