From 25e0fb5f64ccde7ffc1a391c13d82eb768296ff1 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 26 Apr 2021 19:53:28 +0200 Subject: [PATCH] Improved random ip generators. --- src/fr/devinsy/logar/app/anonymizer/Ipv4Generator.java | 9 +++++++-- src/fr/devinsy/logar/app/anonymizer/Ipv6Generator.java | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/fr/devinsy/logar/app/anonymizer/Ipv4Generator.java b/src/fr/devinsy/logar/app/anonymizer/Ipv4Generator.java index 9a6ae0f..a26d25b 100644 --- a/src/fr/devinsy/logar/app/anonymizer/Ipv4Generator.java +++ b/src/fr/devinsy/logar/app/anonymizer/Ipv4Generator.java @@ -19,6 +19,7 @@ package fr.devinsy.logar.app.anonymizer; import org.apache.commons.lang3.RandomUtils; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -236,13 +237,17 @@ public final class Ipv4Generator { result = null; } + else if (StringUtils.equalsAny(ip, "0.0.0.0", "127.0.0.1")) + { + result = ip; + } else { result = random(ip.length()); - if (result.equals(ip)) + while (StringUtils.equals(result, ip)) { - random(ip); + result = random(ip); } } diff --git a/src/fr/devinsy/logar/app/anonymizer/Ipv6Generator.java b/src/fr/devinsy/logar/app/anonymizer/Ipv6Generator.java index 6a9f856..8591157 100644 --- a/src/fr/devinsy/logar/app/anonymizer/Ipv6Generator.java +++ b/src/fr/devinsy/logar/app/anonymizer/Ipv6Generator.java @@ -19,6 +19,7 @@ package fr.devinsy.logar.app.anonymizer; import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -80,9 +81,9 @@ public final class Ipv6Generator } result = buffer.toString(); - if (result.equals(ip)) + while (StringUtils.equals(result, ip)) { - random(ip); + result = random(ip); } }