-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListNets.java
30 lines (27 loc) · 1.33 KB
/
ListNets.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.io.*;
import java.net.*;
import java.util.*;
import static java.lang.System.out;
public class ListNets {
public static void main(String args[]) throws SocketException {
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface netint : Collections.list(nets))
displayInterfaceInformation(netint);
}
static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {
out.printf("Display name: %s\n", netint.getDisplayName());
out.printf("Name: %s\n", netint.getName());
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
for (InetAddress inetAddress : Collections.list(inetAddresses)) {
out.printf("InetAddress: %s%s%s\n", inetAddress.getHostAddress(),
inetAddress.isLoopbackAddress()?" (loopback)":"",
inetAddress.isLinkLocalAddress()?" (linklocal)":"");
}
List<InterfaceAddress> ifAddresses = netint.getInterfaceAddresses();
for (InterfaceAddress ifAddress : ifAddresses) {
out.printf("InterfaceAddress: %s/%d\n", ifAddress.getAddress(),ifAddress.getNetworkPrefixLength());
out.printf("Broadcast: %s\n", ifAddress.getBroadcast());
}
out.printf("\n");
}
}