-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use majority for observer's view change.
utility for listing network interfaces
- Loading branch information
1 parent
aa6d0b2
commit 8f6a81c
Showing
4 changed files
with
62 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
protocols/src/main/java/com/salesforce/apollo/protocols/ListNIFs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.salesforce.apollo.protocols; | ||
|
||
import java.net.InetAddress; | ||
import java.net.NetworkInterface; | ||
import java.net.SocketException; | ||
import java.util.Collections; | ||
import java.util.Enumeration; | ||
|
||
import static java.lang.System.out; | ||
|
||
/** | ||
* @author hal.hildebrand | ||
**/ | ||
public class ListNIFs { | ||
public static void main(String[] args) throws SocketException { | ||
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); | ||
|
||
for (NetworkInterface netIf : Collections.list(nets)) { | ||
out.printf("Display name: %s\n", netIf.getDisplayName()); | ||
out.printf("Name: %s\n", netIf.getName()); | ||
var addresses = netIf.getInterfaceAddresses(); | ||
for (var add : addresses) { | ||
out.printf("Address: %s\n", add); | ||
} | ||
displaySubInterfaces(netIf); | ||
out.print("\n"); | ||
} | ||
} | ||
|
||
static void displaySubInterfaces(NetworkInterface netIf) throws SocketException { | ||
Enumeration<NetworkInterface> subIfs = netIf.getSubInterfaces(); | ||
for (NetworkInterface subIf : Collections.list(subIfs)) { | ||
out.printf("\tSub Interface Display name: %s\n", subIf.getDisplayName()); | ||
out.printf("\tSub Interface Name: %s\n", subIf.getName()); | ||
Enumeration<InetAddress> inetAddresses = subIf.getInetAddresses(); | ||
for (InetAddress add : Collections.list(inetAddresses)) { | ||
out.printf("\t Sub Interface Address: %s\n", add.getHostAddress()); | ||
} | ||
} | ||
} | ||
} |