Sample code for 30+ languages & platforms
Zig

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 Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    const socket = try chilkat.Socket.init();
    defer socket.deinit();

    // Populate a JsonObject with information about the local network adapters, including IPv4 addresses,
    // IPv6 addresses, and MAC addresses.
    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    socket.getAdaptersAddresses(json) catch {
        std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
        return;
    };

    json.setEmitCompact(false);
    const json_str = try json.emit(alloc);
    std.debug.print("{s}\n", .{json_str});
    // JSON parsing code for this result can be generated at Chilkat's online tool:
    // https://tools.chilkat.io/jsonParse
}