Created
September 17, 2020 16:13
-
-
Save jbaiter/948759a5e84c9e21f50452352d69f472 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String anonymizeIp(def ip) { | |
if (ip.contains(':')) { | |
try { | |
StringTokenizer tok = new StringTokenizer(ip, ':'); | |
String firstGroup = tok.nextToken(); | |
String secondGroup = tok.nextToken(); | |
String thirdGroup = tok.nextToken(); | |
return firstGroup + ":" + secondGroup + ":" + thirdGroup + ":0:0:0:0:0"; | |
} catch (Exception e) { | |
return "0:0:0:0:0:0:0:0"; | |
} | |
} else { | |
try { | |
StringTokenizer tok = new StringTokenizer(ip, '.'); | |
String firstGroup = tok.nextToken(); | |
String secondGroup = tok.nextToken(); | |
return firstGroup + "." + secondGroup + "." + "0.0"; | |
} catch (Exception e) { | |
return "0.0.0.0"; | |
} | |
} | |
} | |
ctx.remote_addr = anonymizeIp(ctx.remote_addr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment