Java InetAddress Check isValidInetAddress(String address)

Here you can find the source of isValidInetAddress(String address)

Description

is Valid Inet Address

License

Open Source License

Declaration

public static boolean isValidInetAddress(String address) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 Robert "Unlogic" Olofsson (unlogic@unlogic.se).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v3
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-3.0-standalone.html
 ******************************************************************************/

import java.net.InetAddress;

import java.net.UnknownHostException;

public class Main {
    public static boolean isValidInetAddress(String address) {

        try {/*  w  w  w. j a  v a 2 s. com*/

            InetAddress.getByName(address);

            return true;

        } catch (UnknownHostException e) {

            return false;
        }
    }
}

Related

  1. isUnicastAddress(@CheckForNull InetAddress address)
  2. isValidAddress(InetAddress address, int timeoutMs)
  3. isValidAddress(InetAddress i, boolean includeLocalAddressesInNoderefs)
  4. isValidAddress(InetAddress i, boolean includeLocalAddressesInNoderefs)
  5. isValidCiscoWildcard(InetAddress wildcard)
  6. isValidInetAddress(String IP)
  7. isValidInetAddress(String ip)
  8. isValidIntranetAddress(InetAddress address)
  9. isValidIpAddress(InetAddress ip)