Java InetAddress Check isMulticastAddress(InetAddress ipAddr)

Here you can find the source of isMulticastAddress(InetAddress ipAddr)

Description

is Multicast Address

License

Open Source License

Declaration

public static boolean isMulticastAddress(InetAddress ipAddr) 

Method Source Code

//package com.java2s;
/*/*from ww  w.j  av  a 2 s  . c om*/
 * NetUtils.java
 *
 * This file is part of the IHMC Util Library
 * Copyright (c) 1993-2016 IHMC.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 (GPLv3) as published by the Free Software Foundation.
 *
 * U.S. Government agencies and organizations may redistribute
 * and/or modify this program under terms equivalent to
 * "Government Purpose Rights" as defined by DFARS 
 * 252.227-7014(a)(12) (February 2014).
 *
 * Alternative licenses that allow for use within commercial products may be
 * available. Contact Niranjan Suri at IHMC (nsuri@ihmc.us) for details.
 */

import java.net.InetAddress;

public class Main {
    public static boolean isMulticastAddress(String ipAddr) {
        try {
            return isMulticastAddress(InetAddress.getByName(ipAddr));
        } catch (Exception e) {
            return false;
        }
    }

    public static boolean isMulticastAddress(InetAddress ipAddr) {
        int firstOctet = ipAddr.getAddress()[0];
        if (firstOctet < 0) {
            firstOctet += 255;
        }
        return ((firstOctet >= 224) && (firstOctet < 240));
    }
}

Related

  1. isLocalAddress(InetAddress address)
  2. isLocalIP(final InetAddress ip1, final InetAddress ip2, final int mask)
  3. isLocalIpAddress(final InetAddress ipAddress)
  4. isLoopbackAddress(InetAddress address)
  5. isLoopbackIp(InetAddress addr)
  6. isOnNetwork(InetAddress host, InetAddress network, byte[] mask)
  7. isPortFree(int port, InetAddress addr)
  8. isPortInUse(InetAddress address, int port, int count)
  9. isPortOpen(InetAddress address, int port)