The HTTP Commons module in the Marketplace used to provide a GetIP action, but this is currently out of date.
I use this Java action based on the GetIP action to get IP addresses.
// BEGIN USER CODE
IContext ctx = this.getContext();
if (ctx.getRuntimeRequest().isPresent()) {
IMxRuntimeRequest req = ctx.getRuntimeRequest().get();
// https://stackoverflow.com/questions/16558869/getting-ip-address-of-client
String xForwardedForHeader = req.getHeader("X-Forwarded-For");
if (xForwardedForHeader == null) {
return req.getRemoteAddr();
} else {
// As of https://en.wikipedia.org/wiki/X-Forwarded-For
// The general format of the field is: X-Forwarded-For: client,
// proxy1, proxy2 ...
// we only want the client
String forwardIp = new StringTokenizer(xForwardedForHeader, ",").nextToken().trim();
boolean validIP = checkIP(forwardIp);
if (validIP) {
return forwardIp;
} else {
Core.getLogger("GetIP").error("Could not parse X-Forwarded-for header to an IP address. Header: "+forwardIp);
return "";
}
}
} else {
return "";
}
// END USER CODE
I hope this helps.