getNetworkAddress

import { getNetworkAddress } from "jsr:@ende/net/get-network-address";

function ยท experimental

function getNetworkAddress(family: Ende.NetworkInterfaceInfo["family"] = IPv4): string | undefined

Gets the IPv4 or IPv6 network address of the machine.

family: Ende.NetworkInterfaceInfo["family"] = IPv4

The IP protocol version of the interface to get the address of.

Returns

The IPv4 network address of the machine or undefined if not found.

Example: Get the IPv4 network address (default)

import { getNetworkAddress } from "@ende/net/unstable-get-network-address";

const hostname = getNetworkAddress()!;

Ende.serve({ port: 0, hostname }, () => new Response("Hello, world!"));

Example: Get the IPv6 network address

import { getNetworkAddress } from "@ende/net/unstable-get-network-address";

const hostname = getNetworkAddress("IPv6")!;

Ende.serve({ port: 0, hostname }, () => new Response("Hello, world!"));

See also

Source