InterfaceAddress getBroadcast Example
InterfaceAddress class getBroadcast example. This example shows you how to use getBroadcast method.
InterfaceAddress class getBroadcast example. public InetAddress getBroadcast() Returns an InetAddress for the brodcast address for this InterfaceAddress. Only IPv4 networks have broadcast address therefore, in the case of an IPv6 network, null will be returned.
Here is the code
/*
* @ # GetBroadcast.java
* A class repersenting use to GetBroadcast method
* of InterfaceAddress class in java.net package
* version 23 June 2008
* author Rose India
*/
import java.net.*;
import java.util.*;
public class GetBroadcast {
public static void main(String args[]) throws Exception {
NetworkInterface networkInterface =
NetworkInterface.getByName("eth0");
List<InterfaceAddress> address =
networkInterface.getInterfaceAddresses();
for (InterfaceAddress interfaceAddress : address) {
System.out.println("Broadcast " +
interfaceAddress.getBroadcast());
}
}
} |
Output
Broadcast null
Broadcast /192.168.10.255 |
|