Here you can find the source of getBroadcastAddresses()
public static List<InetAddress> getBroadcastAddresses()
//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.ArrayList; import java.util.Enumeration; import java.util.List; public class Main { /**/* www .j a v a 2 s . c o m*/ * Retrives all the broadcast address of the machine (depending of the different network interfaces) * @return an arraylist of broadcast addresses */ public static List<InetAddress> getBroadcastAddresses() { List<InetAddress> addresses = new ArrayList<>(); Enumeration<NetworkInterface> interfaces; try { interfaces = NetworkInterface.getNetworkInterfaces(); } catch (SocketException ex) { return addresses; } for (NetworkInterface networkInterface = interfaces.nextElement(); interfaces .hasMoreElements(); networkInterface = interfaces .nextElement()) try { if (networkInterface.isLoopback()) continue; for (InterfaceAddress interfaceAddress : networkInterface .getInterfaceAddresses()) { InetAddress broadcast = interfaceAddress.getBroadcast(); if (broadcast == null) continue; addresses.add(broadcast); } } catch (SocketException ex) { //empty } return addresses; } }