-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyAddress.java
27 lines (25 loc) · 1.26 KB
/
MyAddress.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
// 3. Write a simple program to list all network interface on the local host.
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;
import java.util.Enumeration;
public class MyAddress {
public static void main(String[] args) {
try {
// Get all network interfaces on the local host
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
// Iterate through the network interfaces
for (NetworkInterface networkInterface : Collections.list(networkInterfaces)) {
System.out.println("Interface Name: " + networkInterface.getName());
System.out.println("Display Name: " + networkInterface.getDisplayName());
System.out.println("Is Up: " + networkInterface.isUp());
System.out.println("Is Loopback: " + networkInterface.isLoopback());
System.out.println("Supports Multicast: " + networkInterface.supportsMulticast());
System.out.println("Is Virtual: " + networkInterface.isVirtual());
System.out.println("--------------------------------");
}
} catch (SocketException e) {
e.printStackTrace();
}
}
}