2 * Copyright (c) 2016 Inocybe Technologies and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.netconf.console.commands;
11 import com.google.common.base.Strings;
12 import java.util.regex.Matcher;
13 import java.util.regex.Pattern;
15 public final class NetconfCommandUtils {
17 private static final Pattern IP_PATTERN = Pattern.compile(
18 "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
19 + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
20 + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
21 + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
23 private NetconfCommandUtils() {
27 public static boolean isPortValid(final String devicePort) {
28 if (Strings.isNullOrEmpty(devicePort)) {
33 port = Integer.parseInt(devicePort);
34 } catch (NumberFormatException e) {
37 return port >= 0 && port <= 65535;
40 public static boolean isIpValid(final String deviceIp) {
41 if (Strings.isNullOrEmpty(deviceIp)) {
44 Matcher matcher = IP_PATTERN.matcher(deviceIp);
45 return matcher.matches();