Code Monkey home page Code Monkey logo

pmp's Introduction

New version .5 supports upnp and pmp - new docs comming

Until the docs are here - look at the example in test.js

This information is for version 2.9

NODE Implementation of the NAT-PMP port mapping protocol

SEE http://miniupnp.free.fr/nat-pmp.html

This should work on all platforms including windows.

Commands:

getExternalAddress([gateway],function(error,result) - returns the external ip address

gateway is optional (just pass an empty string or null if you do not know the address)
If you do know the address it does speed things up - otherwise it will try to find it.

error returns an error number or 0 if successful


result is an object

result.externalIP = the external IP address
result.error = error text if any

usage

var pmp = require('pmp');
pmp.getExternalAddress('',function(err,rslt){
    console.log(err,rslt);
});

portMap([gateway],localport,externalport,ttl,function(error,result) - maps an external port to a local port

gateway is optional (just pass an empty string or null if you don't know the address)
If you do know the address it does speed things up - otherwise it will try to find it.

localport is the port on the local machine you want to map to - sometimes know as the private port.

externalport is the port of the externalIP that you want the local port mapped to.

ttl is the time in seconds you want this mapping to remain effective.

pmp.portMap('',3000,3000,20,function(err,rslt){1
    console.log(err,rslt);
});

 result is an object

    result.externalIP = the external IP address
    result.error = error text if any
    result.privatePort = the port you gave (local port)
    result.publicPort = the external port - IT COULD BE DIFFERENT then the external port you requested
                        the RFC allows the router to assign an alternate if the one you requested is not available
    result.ttl = how long the mapping will remain active
    result.portMappingInitialized = time in seconds since the port mapping table was initialized (usually router uptime)
    result.gateway = the router address
    result.error = the error text if things did not work

pmp's People

Contributors

stevewitz avatar twitzel avatar

Watchers

 avatar  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.