Clean useful code.
This commit is contained in:
parent
e1cf7fd209
commit
0bed68260a
2 changed files with 73 additions and 4 deletions
|
@ -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;
|
||||
|
|
73
src/fr/devinsy/statoolinfos/util/IpUtils.java
Normal file
73
src/fr/devinsy/statoolinfos/util/IpUtils.java
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue