blob: f951d17c0d01084611e5ee1ec5ab11c85b2f09fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
package org.traccar.helper;
import javax.servlet.http.HttpServletRequest;
public final class ServletHelper {
private ServletHelper() {
}
public static String retrieveRemoteAddress(HttpServletRequest request) {
if (request != null) {
String ipAddress = request.getHeader("X-FORWARDED-FOR");
if (ipAddress != null && !ipAddress.isEmpty()) {
return ipAddress.substring(0, ipAddress.indexOf(",")); //Removes the additional data
} else {
ipAddress = request.getRemoteAddr();
return ipAddress;
}
} else {
return null;
}
}
}
|