net_adm(3)

πŸ“¦
version 29.0.6 Β· 3 versions
, in ubuntu stonking

πŸ’– NAME πŸ’–

net_adm β€” Various Erlang net administration routines.

okay so bestie, this is the Erlang module that handles all your network-admin-y business. she's the friend who knows everyone's IP, no cap πŸ‘‘


✨ DESCRIPTION ✨

This module contains various network utility functions.

that's it, that's the official description β€” she's a whole toolbox of network utilities and she doesn't need to flex about it πŸ’…

πŸ“ Files

File .hosts.erlang consists of a number of host names written as Erlang terms. It is looked for in the current work directory, the user's home directory, and $OTPROOT (the root directory of Erlang/OTP), in that order.

like, the search order is a whole queue and the current work directory is first in line πŸŽ€

The format of file .hosts.erlang must be one host name per line. The host names must be within quotes.

yes, quoted. the quotes are not optional, she's serious about that 😀

Example:

^ (new line)

🧬 DATA TYPES 🧬

  • verbosity() :: silent | verbose. β€” literally two moods and that's it: quiet girl or yapper πŸ’¬

🌈 FUNCTIONS 🌈

πŸ¦‹ dns_hostname(Host)

dns_hostname(Host) -> {ok, Name} | {error, Host}
                      when Host :: atom() | string(), Name :: string().

Returns the official name of Host, or {error, Host} if no such name is found. See also inet.

so if she knows the glow-up name, you get {ok, Name}. if she doesn't? {error, Host} and she hands you back the host you gave her, no notes πŸ™ˆ also go peek at inet while you're here.


πŸ¦‹ host_file()

host_file() -> Hosts | {error, Reason}
                    when
                        Hosts :: [Host :: atom()],
                        Reason ::
                            file:posix() |
                            badarg | terminated | system_limit |
                            {Line :: integer(),
                             Mod :: module(),
                             Term :: term()}.

Reads file .hosts.erlang, see section Files. Returns the hosts in this file as a list. Returns {error, Reason} if the file cannot be read or the Erlang terms on the file cannot be interpreted.

it just goes and reads that file and gives you back the hosts as a list. if the file won't read, or the Erlang terms in it are giving nonsense, you get {error, Reason} instead β€” and yeah, the Reason can be a whole tuple with the Line, the Mod, and the Term that did it, so you can go track down the exact line that ruined the vibe πŸ’€


πŸ¦‹ localhost()

localhost() -> Name when Name :: string().

Returns the name of the local host. If Erlang was started with command-line flag -name, Name is the fully qualified name.

if you started Erlang with the -name flag, she gives you the fully qualified name β€” the whole government name, not the nickname 😭


πŸ¦‹ names(Host)

names(Host) -> {ok, [{Name, Port}]} | {error, Reason}
               when
                   Host :: atom() | string() | inet:ip_address(),
                   Name :: string(),
                   Port :: non_neg_integer(),
                   Reason :: address | file:posix().

Returns the names and associated port numbers of the Erlang nodes that epmd registered at the specified host.

Similar to epmd -names, see erts:epmd.

Returns {error, address} if epmd is not operational.

if epmd isn't even running you get {error, address} β€” like showing up to the party and the lights are off πŸ’€

Example:

(arne@dunn)1> net_adm:names().
{ok,[{"arne",40262}]}

look at her, names AND ports, iconic ✨


πŸ¦‹ ping(Node)

ping(Node) -> pong | pang when Node :: atom().

Sets up a connection to Node. Returns pong if it is successful, otherwise pang.

pong = she's up, connection slayed. pang = she ghosted you. simple as that πŸ“


πŸ¦‹ world(Arg)

world(Arg) -> [node()] when Arg :: verbosity().

Calls names(Host) for all hosts that are specified in the Erlang host file .hosts.erlang, collects the replies, and then evaluates ping(Node) on all those nodes. Returns the list of all nodes that are successfully pinged.

If Arg == verbose, the function writes information about which nodes it is pinging to stdout.

This function can be useful when a node is started, and the names of the other network nodes are not initially known.

Returns {error, Reason} if host_file/0 returns {error, Reason}.

she's the social butterfly fr fr: hits names(Host) on every host in .hosts.erlang, collects all the replies, then runs ping(Node) on every single node and hands you back only the ones that actually answered. pass verbose as Arg and she'll narrate who she's pinging straight to stdout πŸ—£οΈ super useful when a node boots up and has zero idea who else is out there. and if host_file/0 comes back with {error, Reason}, that error just travels right up to you πŸ”₯


πŸ¦‹ world_list(Hosts, Arg)

world_list(Hosts, Arg) -> [node()]
                    when Hosts :: [atom()], Arg :: verbosity().

Same as world/0,1, but the hosts are specified as argument instead of being read from .hosts.erlang.

same energy as world/0,1, except you hand her the host list yourself instead of making her go read .hosts.erlang. main character behavior: you curate the guest list πŸ‘‘πŸ«Ά


and that's the whole page bestie, you ate it πŸ’… this was Ericsson AB's net_adm(3) from kernel 11.0.3 β€” go forth and ping responsibly πŸ’–βœ¨πŸŒΈ

πŸ“¦ where this page comes from