Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.net.InetAddress; import java.net.MulticastSocket; import java.net.NetworkInterface; import java.util.Enumeration; public class JavaMulticastSocketgetInterfaceExample1 { public static void main(String[] args) throws IOException { MulticastSocket ms1 = new MulticastSocket(); NetworkInterface nif1 = NetworkInterface.getByIndex(1); Enumeration
enu = nif1.getInetAddresses(); InetAddress intadd = enu.nextElement(); ms1.setInterface(intadd); System.out.println("Interface : " + ms1.getInterface());//getting the address of the network interface } }
Output