NAT traversal library for Erlang/OTP supporting UPnP IGD, NAT-PMP, and PCP protocols.
Full documentation: benoitc.github.io/erlang-nat
- Multiple Protocols: UPnP IGD (v1 & v2), NAT-PMP, PCP
- Auto-renewal: Port mappings are automatically renewed before expiry
- Event System: Get notified of mapping changes and IP changes
- IPv6 Support: Full IPv6 support via PCP protocol
- OTP Application: Runs as a supervised OTP application
%% 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).- Erlang/OTP 26 or later
- rebar3
MIT License - see LICENSE for details.