集册 Java实例教程 是IPv4或IPv6文本地址

是IPv4或IPv6文本地址

欢马劈雪     最近更新时间:2020-01-02 10:19:05

475
是IPv4或IPv6文本地址

/*

 *

 * Licensed to the Apache Software Foundation (ASF) under one or more

 * contributor license agreements.  See the NOTICE file distributed with

 * this work for additional information regarding copyright ownership.

 * The ASF licenses this file to You 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 edu.nwpu.gemfire.monitor.util;
/**
N o w J a v a . c o m - 时  代  Java 提供 
**/


import java.util.regex.Matcher;

import java.util.regex.Pattern;

import java.util.regex.PatternSyntaxException;


/* [ NOTE: 

 * This class supposed to be removed, if required, after discussing with 

 * VMware team ]

 */

/**

 * Class IPAddressUtil This is utility class for checking whether ip address is

 * versions i.e. IPv4 or IPv6 address

 * 

 * @author Sachin K

 * 

 * @since version 7.0.1

 */

public class IPAddressUtil {
//from 时 代 J a v a 公 众 号 - nowjava.com

    private static Pattern VALID_IPV4_PATTERN = null;

    private static Pattern VALID_IPV6_PATTERN = null;

    private static final String ipv4Pattern = "(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])";

    private static final String ipv6Pattern = "([0-9a-f]{1,4}:){7}([0-9a-f]){1,4}";


    static {

        try {

            VALID_IPV4_PATTERN = Pattern.compile(ipv4Pattern,

                    Pattern.CASE_INSENSITIVE);

            VALID_IPV6_PATTERN = Pattern.compile(ipv6Pattern,

                    Pattern.CASE_INSENSITIVE);

        } catch (PatternSyntaxException e) {


        }

    }


    public static Boolean isIPv4LiteralAddress
展开阅读全文