Determining whether an IP address is a multicast address

A multicast address is an ip address used to denote multiple recepients. They fall in the range 224.0.0.1 to 239.255.255.255. You can use invoke the method isMulticastAddress on an instance of InetAddress to determine whether the specified address falls within that range.

Main.java:

import java.net.*;
 
public class Main {
   public static void main(String args[]) {
      try {
         InetAddress address1 = InetAddress.getByName("205.178.180.16");
         InetAddress address2 = InetAddress.getByName("224.120.50.1");
 
         System.out.println(address1.isMulticastAddress());
         System.out.println(address2.isMulticastAddress());
      }
      catch(UnknownHostException e) {
         System.out.println(e);
      }
   }
}

outputs:

false
true