Java
Java
Get Local Network Adapter Addresses
See more Socket/SSL/TLS Examples
Demonstrates Socket.GetAdaptersAddresses, which populates a JsonObject with information about local network adapters, including IPv4 addresses, IPv6 addresses, and MAC addresses.
Tip: Code to parse the returned JSON can be generated with Chilkat's online tool at https://tools.chilkat.io/jsonParse.
Background. This provides a portable way to enumerate the host's network interfaces and their addresses.
Chilkat Java Downloads
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
CkSocket socket = new CkSocket();
// Populate a JsonObject with information about the local network adapters, including IPv4 addresses,
// IPv6 addresses, and MAC addresses.
CkJsonObject json = new CkJsonObject();
success = socket.GetAdaptersAddresses(json);
if (success == false) {
System.out.println(socket.lastErrorText());
return;
}
json.put_EmitCompact(false);
String jsonStr = json.emit();
System.out.println(jsonStr);
// JSON parsing code for this result can be generated at Chilkat's online tool:
// https://tools.chilkat.io/jsonParse
}
}