Here you can find the source of getBroadcast()
public static String getBroadcast() throws SocketException
//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; } }