erlang-nat

NAT traversal library for Erlang/OTP supporting UPnP IGD, NAT-PMP, and PCP protocols.

Hex.pmGitHub Actions

Documentation

Full documentation: benoitc.github.io/erlang-nat

Features

Quick Start

%% Add to your rebar.config
{deps, [{nat, "0.5.2"}]}.
%% Start the application
application:ensure_all_started(nat).

%% Discover NAT gateway
ok = nat:discover().

%% Get external IP
{ok, ExtIp} = nat:get_external_address().

%% Add port mapping (auto-renewed)
{ok, _Since, 8333, 8333, 3600} = nat:add_port_mapping(tcp, 8333, 8333).

%% Register for events
nat:reg_pid(self()).
receive
    {nat_event, {ip_changed, OldIp, NewIp}} ->
        io:format("IP changed: ~s -> ~s~n", [OldIp, NewIp])
end.

%% Delete mapping
ok = nat:delete_port_mapping(tcp, 8333, 8333).

Requirements

License

MIT License - see LICENSE for details.

Support