I am supposed to **capture the ip address of the client machine**, who hits my web application.
After googling, I have found two ways :

1. `request.getRemoteAddr()`
2. `request.getHeader("X-FORWARDED-FOR")`

but both of them do not guarantee returning the actual ip of the client machine.
Also, I am supposed to achieve the same using **struts1.2**, as the application is developed in struts1.2.

Is there any struts class for the same?

I am using the following code:

```
String ipAddress = request.getHeader("X-FORWARDED-FOR");  
if (ipAddress == null) {  
    ipAddress = request.getRemoteAddr();  
}

```

but the method `request.getHeader("X-FORWARDED-FOR");` returns `null` when I access the application from a mobile or wireless device.

As a result, ip is obtained from method `request.getRemoteAddr();`
The issue is the ip retrieved is private and **not public**
but i want the **public ip** of client.