Java Network Interface Get getBroadcast()

Here you can find the source of getBroadcast()

Description

get Broadcast

License

Open Source License

Declaration

public static String getBroadcast() throws SocketException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

public class Main {
    public static String getBroadcast() throws SocketException {
        System.setProperty("java.net.preferIPv4Stack", "true");
        for (Enumeration<NetworkInterface> niEnum = NetworkInterface.getNetworkInterfaces(); niEnum
                .hasMoreElements();) {//w w  w. j a  v a  2 s. co  m
            NetworkInterface ni = niEnum.nextElement();
            if (!ni.isLoopback()) {
                for (InterfaceAddress interfaceAddress : ni.getInterfaceAddresses()) {
                    InetAddress bcast = interfaceAddress.getBroadcast();
                    if (bcast != null) {
                        return bcast.toString().substring(1);
                    }
                }
            }
        }
        return null;
    }
}

Related

  1. getAllInterfaces()
  2. getAllInterfaces()
  3. getAllLocalInterfaces()
  4. getAllLocalUsingNetworkInterface()
  5. getAvailableNetworkInterface()
  6. getCustomMACFormat(NetworkInterface inte)
  7. getDefaultInterface()
  8. getDefaultNetworkInterface()
  9. getFirstMACAdress()