Dimitris,
On 11/12/25 9:21 AM, Dimitris Soumis wrote:
On Wed, Nov 12, 2025 at 4:03 PM Christopher Schultz <
[email protected]> wrote:
>>>> I can also post my interface info class source if anyone is interested
in what their system interfaces loo like to Windows.
This could help identify possible edge cases.
Here it is.
I didn't include some of the address flags like the various flavors of
multicast. I also didn't include "anylocal" but since that's interesting
to us, I think I'll add it.
-chris
import java.io.PrintStream;
import java.net.*;
import java.util.*;
import java.util.stream.Collectors;
public class InterfaceInfo {
private static void usage(PrintStream out) {
out.println("Usage: java " + InterfaceInfo.class + " [options]");
out.println();
out.println("Shows information for all network interfaces and
addresses on the system.");
out.println();
out.println("Options:");
out.println(" -f, --filter <chars> Filter interfaces by
flags (see key below).");
out.println(" -h, --help Show this help text
and exit.");
out.println(" -v, --verbose Print more
information.");
out.println();
out.println("Meanings of flag characters:");
out.println(" u Up - Interface is enabled and able
to accept communictions.");
out.println(" L Loopback - Interface only sends packets
back to this system.");
out.println(" V Virtual - Interface is not tied to a
physical hardware device.");
out.println(" P Point-to-point- Interface is connected to a
single remote endpoint.");
out.println(" M Multicast - Interface supports multi-cast
communication.");
out.println(" n Link-local- Address is valid only on the
local network segment.");
out.println(" s Site-local- Address is private/internal.");
out.println(" l Loopback - Address only sends packets back
to this system.");
out.println(" m Multicast - Address is multi-cast capable.");
}
public static void main(String[] args) throws Exception {
boolean verbose = false;
String filterFlags = null;
int argindex = 0;
while(argindex < args.length) {
String arg = args[argindex++];
if ("--filter".equals(arg) || "-f".equals(arg)) {
filterFlags = args[argindex++];
} else if("--verbose".equals(arg) || "-v".equals(arg)) {
verbose = true;
} else if("--help".equals(arg) || "-h".equals(arg)) {
usage(System.out);
System.exit(0);
}
}
Enumeration<NetworkInterface> interfaces =
NetworkInterface.getNetworkInterfaces();
if (interfaces == null) {
System.out.println("No network interfaces found.");
System.exit(0);
}
List<Record> records = new ArrayList<>();
// Track maximum field widths for neat output
int maxName = "Name".length();
int maxDisp = "DisplayName".length();
int maxAddr = "Address".length();
int maxType = "Type".length();
int maxMTU = "MTU".length();
int maxMAC = "MAC".length();
// First pass: gather info and measure column widths
while (interfaces.hasMoreElements()) {
NetworkInterface netIf = interfaces.nextElement();
String name = netIf.getName();
String display = netIf.getDisplayName();
String mac = formatMacAddress(netIf.getHardwareAddress());
boolean up = netIf.isUp();
boolean loop = netIf.isLoopback();
boolean virt = netIf.isVirtual();
boolean p2p = netIf.isPointToPoint();
boolean mcst = netIf.supportsMulticast();
int mtu = netIf.getMTU();
Enumeration<InetAddress> addrs = netIf.getInetAddresses();
if (!addrs.hasMoreElements()) {
records.add(new Record(name, display, "N/A", "N/A",
mtu, mac,
up, loop, virt, p2p, mcst,
false, false, false, false));
} else {
while (addrs.hasMoreElements()) {
InetAddress addr = addrs.nextElement();
String type = (addr instanceof Inet4Address) ? "IPv4" :
(addr instanceof Inet6Address) ? "IPv6" : "?";
String address = addr.getHostAddress();
records.add(new Record(name, display, address,
type, mtu, mac,
up, loop, virt, p2p, mcst,
addr.isLinkLocalAddress(),
addr.isSiteLocalAddress(),
addr.isLoopbackAddress(),
addr.isMulticastAddress()));
// update max widths
maxName = Math.max(maxName, name.length());
maxDisp = Math.max(maxDisp, display.length());
maxAddr = Math.max(maxAddr, address.length());
maxType = Math.max(maxType, type.length());
maxMTU = Math.max(maxMTU,
String.valueOf(mtu).length());
maxMAC = Math.max(maxMAC, mac.length());
}
}
}
// Apply filters
if (filterFlags != null) {
Set<Character> filters = filterFlags.chars()
.mapToObj(c -> (char)c)
.collect(Collectors.toSet())
;
records = records.stream()
.filter(r -> matchesFilter(r, filters))
.collect(Collectors.toList())
;
}
if (verbose) {
System.out.printf(
"%-" + maxName + "s %-" + maxDisp + "s %-" +
maxAddr + "s"
+ "%-" + maxType + "s %-5s %-9s %-8s %-8s %-9s
%-10s"
+ " %-10s %-10s %-10s %-" + maxMTU + "s %-" +
maxMAC + "s%n",
"Name", "DisplayName", "Address", "Type",
"Up", "Loopback", "Virtual", "P2P", "MCast",
"LinkLocal", "SiteLocal", "AddrLoop", "AddrMCast",
"MTU", "MAC");
for (Record r : records) {
System.out.printf(
"%-" + maxName + "s %-" + maxDisp + "s %-" +
maxAddr + "s "
+ " %-" + maxType + "s %-5s %-9s %-8s %-8s
%-9s %-10s"
+" %-10s %-10s %-10s %-" + maxMTU + "d %-"
+ maxMAC + "s%n",
r.name, r.displayName, r.address, r.type,
r.up, r.loopback, r.virtual, r.p2p, r.mcst,
r.linkLocal, r.siteLocal, r.loopAddr, r.multiAddr,
r.mtu, r.mac);
}
} else {
System.out.printf("%-" + maxName + "s %-" + maxAddr + "s
U L V P M n s l m%n",
"Name", "Address");
for (Record r : records) {
System.out.printf("%-" + maxName + "s %-" + maxAddr +
"s %s %s %s %s %s %s %s %s %s%n",
r.name, r.address,
yn(r.up), yn(r.loopback), yn(r.virtual),
yn(r.p2p), yn(r.mcst),
yn(r.linkLocal), yn(r.siteLocal),
yn(r.loopAddr), yn(r.multiAddr));
}
}
}
private static String yn(boolean b) {
return b ? "Y" : "N";
}
private static boolean matchesFilter(Record r, Set<Character>
filterFlags) {
for (char f : filterFlags) {
switch (f) {
case 'U': if (!r.up) return false; break;
case 'L': if (!r.loopback) return false; break;
case 'V': if (!r.virtual) return false; break;
case 'P': if (!r.p2p) return false; break;
case 'M': if (!r.mcst) return false; break;
case 'n': if (!r.linkLocal) return false; break;
case 's': if (!r.siteLocal) return false; break;
case 'l': if (!r.loopAddr) return false; break;
case 'm': if (!r.multiAddr) return false; break;
default:
System.err.println("Warning: unrecognized filter
flag '" + f + "'");
return false;
}
}
return true;
}
// Record to hold interface and address details
private static class Record {
String name, displayName, address, type, mac;
int mtu;
boolean up, loopback, virtual, p2p, mcst;
boolean linkLocal, siteLocal, loopAddr, multiAddr;
Record(String name, String displayName, String address, String
type, int mtu, String mac,
boolean up, boolean loopback, boolean virtual, boolean
p2p, boolean mcst,
boolean linkLocal, boolean siteLocal, boolean loopAddr,
boolean multiAddr) {
this.name = name;
this.displayName = displayName;
this.address = address;
this.type = type;
this.mtu = mtu;
this.mac = mac;
this.up = up;
this.loopback = loopback;
this.virtual = virtual;
this.p2p = p2p;
this.mcst = mcst;
this.linkLocal = linkLocal;
this.siteLocal = siteLocal;
this.loopAddr = loopAddr;
this.multiAddr = multiAddr;
}
}
private static String formatMacAddress(byte[] mac) {
if (mac == null) return "N/A";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format("%02X%s", mac[i], (i < mac.length -
1) ? ":" : ""));
}
return sb.toString();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]