Skip to content

networkInterfaces ​

networkInterfaces returns one NetworkInterface per local IP address found on every active network adapter, an adapter with both an IPv4 and an IPv6 address contributes two entries. Enumeration failures return Err(OsError) with code ERR_OS_NETWORK_INTERFACES_FAILED.

SignaturenetworkInterfaces(): Result<NetworkInterface[], OsError>
tyrus
import { NetworkInterface, OsError, networkInterfaces } from "tyrus:os";

const result: Result<NetworkInterface[], OsError> = networkInterfaces();
match (result) {
    Ok(interfaces) => { print(`${interfaces.length} address(es)`); }
    Err(error) => { printError(error.code); }
}

NetworkInterface Fields ​

FieldTypeMeaning
namestringThe adapter's name (e.g. "eth0", "en0", "Wi-Fi").
addressstringThe local IP address.
netmaskstringThe subnet mask for address.
familystringEither "IPv4" or "IPv6".