Java IP Address Validate isIpValid(final String deviceIp)

Here you can find the source of isIpValid(final String deviceIp)

Description

is Ip Valid

License

Open Source License

Declaration

public static boolean isIpValid(final String deviceIp) 

Method Source Code


//package com.java2s;
/*/*from ww w  .  j a va 2  s. c  o  m*/
 * Copyright (c) 2016 Inocybe Technologies and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.common.base.Strings;

public class Main {
    private static final Pattern IP_PATTERN = Pattern
            .compile("^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
                    + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");

    public static boolean isIpValid(final String deviceIp) {
        if (Strings.isNullOrEmpty(deviceIp)) {
            return false;
        }
        Matcher matcher = IP_PATTERN.matcher(deviceIp);
        return matcher.matches();
    }
}

Related

  1. isIPv6HexCompressedAddress(final String input)
  2. isIPv6HexCompressedAddress(String ip)
  3. isIPv6LiteralAddress(String src)
  4. isIpV6RegexValid(String strIp)
  5. isIPv6StdAddress(final String input)
  6. isIPValid(final String ipv4)
  7. isIpValid(String ip)