Coder Social home page Coder Social logo

erlang-nat's Introduction

nat - implements NAT handling facilities

Copyright (c) 2016-2018 Benoît Chesneau.

Version: 0.3.1

nat

Library that implements NAT facilities.

Currently supported protocols:

  • natpmp
  • UPNP v1
  • UPNP v2

Usage

Discover the NAT gateway:

You should start by discovering the NAT gateway if it exists:

1> {ok, Ctx} = nat:discover().
{ok,{natupnp_v1,{nat_upnp,"http://192.168.1.254:5678/control/wan_ip_connection",
                          "192.168.1.22"}}}

If OK you will be able to use the context in other functions. For example to get the external gateway:

2> nat:get_external_address(Ctx).
{ok,"88.163.70.217"}

And the local IP associated to this:

3> nat:get_internal_address(Ctx).
{ok,"192.168.1.22"}

Map an External IP Address

{ok, Ctx} = nat:discover(),
Protocol = tcp,
InternalPort = 80,
ExternalPortRequest = 8080,
Lifetime = 3600,

{ok, Since, InternalPort, ExternalPortRequest, MappingLifetime} = \
    nat:add_port_mapping(Ctx, Protocol, InternalPort, ExternalPortRequest, Lifetime).

This map the port 80 to the port 8080.

Note: pass 0 to the ExternalPortRequest to ask to the router to create a dynamic port.

Remove a port mapping

ok = nat:delete_port_mapping(Ctx, Protocol, InternalPort, ExternalPort)

Contribute

For issues, comments or feedback please create an issue.

Modules

nat
nat_lib
natpmp
natupnp_v1
natupnp_v2

erlang-nat's People

Contributors

benoitc avatar macpie avatar getong avatar vagabond avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.