Skip to content

Commit 7033192

Browse files
authored
EgressDiagnostics: correctly display mac address (#58)
1 parent 3d60464 commit 7033192

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/main/java/test/EgressDiagnostics.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static void tryRemote(InetSocketAddress remote) {
3939
System.out.println("local: " + local);
4040
NetworkInterface ni = NetworkInterface.getByInetAddress(local);
4141
System.out.println("interface: " + ni);
42-
System.out.println("hardware: " + (ni == null ? null : ni.getHardwareAddress().toString().substring(3)));
42+
System.out.println("hardware: " + (ni == null ? null : macBytesToHex(ni.getHardwareAddress())));
4343
} catch (Throwable t) {
4444
System.out.println(t);
4545
t.printStackTrace();
@@ -49,4 +49,12 @@ public static void tryRemote(InetSocketAddress remote) {
4949
}
5050
}
5151
}
52+
53+
public static String macBytesToHex(byte[] bytes) {
54+
StringBuilder sb = new StringBuilder();
55+
for (int i = 0; i < bytes.length; i++) {
56+
sb.append(String.format("%02X%s", bytes[i], (i < bytes.length - 1) ? "-" : ""));
57+
}
58+
return sb.toString();
59+
}
5260
}

0 commit comments

Comments
 (0)