/*
 * Symphony - A modern community (forum/SNS/blog) platform written in Java.
 * Copyright (C) 2012-2017,  b3log.org & hacpai.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.b3log.symphony.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;

/**
 * Network utilities.
 *
 * @author <a href="http://88250.b3log.org">Liang Ding</a>
 * @version 1.0.1.0, Sep 17, 2015
 * @since 1.3.0
 */
public final class Networks {

    /**
     * Is IPv4.
     *
     * @param ip ip
     * @return {@code true} if it is, returns {@code false} otherwise
     */
    public static boolean isIPv4(final String ip) {
        if (StringUtils.isBlank(ip)) {
            return false;
        }

        final String regex = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
                + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
                + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
                + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";

        final Pattern pattern = Pattern.compile(regex);
        final Matcher matcher = pattern.matcher(ip);

        return matcher.matches();
    }

    /**
     * Private constructor.
     */
    private Networks() {
    }
}

@@ -1028,25 +1028,24 @@
 1.0.
-1
+2
 .0, 
-Sep 17
+Mar 2
 , 201
-5
+7
 %0A * 
@@ -1385,88 +1385,21 @@
  %22%5E(
-1%5C%5Cd%7B2%7D%7C2%5B0-4%5D%5C%5Cd%7C25%5B0-5%5D%7C%5B1-9%5D%5C%5Cd%7C%5B1-9%5D)%5C%5C.%22%0A                + %22(00
+(%5B01%5D
 ?%5C%5Cd
-%7C1
 %5C%5Cd
-%7B2%7D
+?
 %7C2%5B0
@@ -1416,132 +1416,29 @@
 0-5%5D
-%7C%5B1-9%5D%5C%5Cd%7C%5C%5Cd)%5C%5C.%22%0A                + %22(00?%5C%5Cd%7C1%5C%5Cd%7B2%7D%7C2%5B0-4%5D%5C%5Cd%7C25%5B0-5%5D%7C%5B1-9%5D
+)%5C%5C.)%7B3%7D(%5B01%5D?
 %5C%5Cd
-%7C
 %5C%5Cd
-)%5C%5C.%22%0A                + %22(00?%5C%5Cd%7C1%5C%5Cd%7B2%7D
+?
 %7C2%5B0
@@ -1455,21 +1455,8 @@
 0-5%5D
-%7C%5B1-9%5D%5C%5Cd%7C%5C%5Cd
 )$%22;

修复 IPv4 判断