com.alibaba.nacos.common.utils.InternetAddressUtil Maven / Gradle / Ivy
The newest version!
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.common.utils;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* ip tool.
*
* @author Nacos
*/
@SuppressWarnings({"checkstyle:AbbreviationAsWordInName", "PMD.ClassNamingShouldBeCamelRule"})
public class InternetAddressUtil {
private InternetAddressUtil() {
}
public static final boolean PREFER_IPV6_ADDRESSES = Boolean.parseBoolean(System.getProperty("java.net.preferIPv6Addresses"));
public static final String IPV6_START_MARK = "[";
public static final String IPV6_END_MARK = "]";
public static final String ILLEGAL_IP_PREFIX = "illegal ip: ";
public static final String IP_PORT_SPLITER = ":";
public static final int SPLIT_IP_PORT_RESULT_LENGTH = 2;
public static final String PERCENT_SIGN_IN_IPV6 = "%";
public static final String LOCAL_HOST = "localhost";
private static final String LOCAL_HOST_IP_V4 = "127.0.0.1";
private static final String LOCAL_HOST_IP_V6 = "[::1]";
private static final String CHECK_OK = "ok";
private static final Pattern DOMAIN_PATTERN = Pattern.compile("[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\\.?");
private static final String IPV4_TUPLE = "(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])";
private static final Pattern IPV4_PATTERN = Pattern
.compile("(?
© 2015 - 2024 Weber Informatics LLC | Privacy Policy