dcsimg
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


advertisement
 

Tip: Identify Whether an IP Address Is a Multicast Address

Use this Java API to figure out whether or not an IP address is a multicast address.


advertisement

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


You may want to know whether an IP address is a multicast address or not in order to make a decision on how to proceed with it. Java supports this with the help of an API called isMulticastAddress().

import java.net.*;

public class MulticastAddress 
{
   public static void main(String args[])
   {
      MulticastAddress multicastAddress = new MulticastAddress();
      multicastAddress.proceed();
   }

   private void proceed() 
   {
      InetAddress addr = null;
      String ipAddress = "224.0.0.5";

      try{
         //You can customize this by passing an argument and check for values in runtime
         addr = InetAddress.getByName(ipAddress);
      }catch(UnknownHostException uhe)
      {
         System.out.println("UnknownHostException: " + uhe);
      }
      
      //This method identifies if the given ipaddress is multicast address or not
      if (addr.isMulticastAddress()) {
         System.out.println(addr + " is multicast address.");
      }
      else
      {
         System.out.println(addr + " is not multicast address.");
      }
   }
}

/*

Expected output:

[root@mypc]# java MulticastAddress
/224.0.0.5 is multicast address.

*/ 

 

Visit the DevX Tip Bank

 





   
Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date