blob: 4eab490014e38c58545d110de661124025449c7b (
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
|
package org.traccar.helper;
import javax.servlet.http.HttpServletRequest;
public final class 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;
}
}
}
|