aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/helper/ServletHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/helper/ServletHelper.java')
-rw-r--r--src/main/java/org/traccar/helper/ServletHelper.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/helper/ServletHelper.java b/src/main/java/org/traccar/helper/ServletHelper.java
new file mode 100644
index 000000000..4eab49001
--- /dev/null
+++ b/src/main/java/org/traccar/helper/ServletHelper.java
@@ -0,0 +1,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;
+ }
+
+
+ }
+} \ No newline at end of file