diff --git a/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLog.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLog.java index dafc30b..82f1bca 100644 --- a/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLog.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLog.java @@ -21,7 +21,6 @@ package fr.devinsy.statoolinfos.metrics.http; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Locale; -import java.util.regex.Pattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,9 +35,6 @@ public class HttpAccessLog { private static Logger logger = LoggerFactory.getLogger(HttpAccessLog.class); - public static final Pattern IPV4_PATTERN = Pattern.compile("\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}"); - public static final Pattern IPV6_PATTERN = Pattern.compile("([0-9a-f]{1,4}:{1,2}){4,7}([0-9a-f]){1,4}", Pattern.CASE_INSENSITIVE); - private String ip; private String remoteUser; private LocalDateTime time; diff --git a/src/fr/devinsy/statoolinfos/util/IpUtils.java b/src/fr/devinsy/statoolinfos/util/IpUtils.java new file mode 100644 index 0000000..36fa32f --- /dev/null +++ b/src/fr/devinsy/statoolinfos/util/IpUtils.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2021 Christian Pierre MOMON + * + * This file is part of StatoolInfos, simple service statistics tool. + * + * StatoolInfos is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * StatoolInfos is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with StatoolInfos. If not, see . + */ +package fr.devinsy.statoolinfos.util; + +import java.util.regex.Pattern; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class IpUtils. + */ +public class IpUtils +{ + private static Logger logger = LoggerFactory.getLogger(IpUtils.class); + + public static final Pattern IPV4_PATTERN = Pattern.compile("\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}"); + public static final Pattern IPV6_PATTERN = Pattern.compile("([0-9a-f]{1,4}:{1,2}){4,7}([0-9a-f]){1,4}", Pattern.CASE_INSENSITIVE); + + private IpUtils() + { + } + + /** + * Checks if is ipv 4. + * + * @param input + * the input + * @return true, if is ipv 4 + */ + public static boolean isIpv4(final String input) + { + boolean result; + + result = IPV4_PATTERN.matcher(input).matches(); + + // + return result; + } + + /** + * Checks if is ipv 6. + * + * @param input + * the input + * @return true, if is ipv 6 + */ + public static boolean isIpv6(final String input) + { + boolean result; + + result = IPV6_PATTERN.matcher(input).matches(); + + // + return result; + } +} \ No newline at end of file