All Projects → alxhotel → nat-api

alxhotel / nat-api

Licence: MIT license
↔️ Fast port mapping with UPnP and NAT-PMP

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to nat-api

Miniupnp
UPnP IGD implementation
Stars: ✭ 974 (+4327.27%)
Mutual labels:  nat, upnp
Internet Hosting Tool
Enable Moonlight streaming from your PC over the Internet with no configuration required
Stars: ✭ 205 (+831.82%)
Mutual labels:  nat, upnp
ssdp
Python asyncio library for Simple Service Discovery Protocol (SSDP).
Stars: ✭ 25 (+13.64%)
Mutual labels:  protocol, upnp
diepssect
A public repo for hacky diep stuff - networking protocol, WebAssembly, memory editing, & physics
Stars: ✭ 26 (+18.18%)
Mutual labels:  protocol
protocol-registry
This module allows you to set custom protocol handler for your nodejs app.
Stars: ✭ 45 (+104.55%)
Mutual labels:  protocol
SwiftArchitectureWithPOP
A base architecture written in swift and protocol oriented, for building new apps easily and quickly
Stars: ✭ 28 (+27.27%)
Mutual labels:  protocol
rconsharp
rconsharp is a Valve RCON protocol implementation written in C# targeting netstandard 2.1
Stars: ✭ 43 (+95.45%)
Mutual labels:  protocol
ministun
A zero dependency STUN server
Stars: ✭ 26 (+18.18%)
Mutual labels:  nat
WSD-python
Web Services for Devices (WSD) tools and utilities for cross platform support
Stars: ✭ 22 (+0%)
Mutual labels:  protocol
PSAVanCanBridge
VAN - CAN protocol bridge (V2C) for cars made by PSA Group (Peugeot, Citroen)
Stars: ✭ 67 (+204.55%)
Mutual labels:  protocol
Rubicon
Swift parser + mock generator
Stars: ✭ 42 (+90.91%)
Mutual labels:  protocol
LXFProtocolTool
由Swift中协议方式实现功能的实用工具库【Refreshable、EmptyDataSetable 支持 Rx 】
Stars: ✭ 101 (+359.09%)
Mutual labels:  protocol
ipfs-companion
Browser extension that simplifies access to IPFS resources on the web
Stars: ✭ 1,745 (+7831.82%)
Mutual labels:  protocol
mmupnp
Universal Plug and Play (UPnP) ControlPoint library for Java/Kotlin
Stars: ✭ 39 (+77.27%)
Mutual labels:  upnp
wayland-explorer
Easily browse and read Wayland protocols documentation
Stars: ✭ 78 (+254.55%)
Mutual labels:  protocol
minecraft-protocol
Library for decoding and encoding Minecraft packets
Stars: ✭ 20 (-9.09%)
Mutual labels:  protocol
metacom
RPC communication protocol for Metarhia stack 🔌
Stars: ✭ 42 (+90.91%)
Mutual labels:  protocol
xcad
Framework for developing CAD applications for SOLIDWORKS, including add-ins, stand-alone applications, macro features, property manager pages, etc.
Stars: ✭ 50 (+127.27%)
Mutual labels:  pmp
rAudio-1
Raspberry Pi audio player: AirPlay, Audio CD, Bluetooth, DAB radio, DSP, Internet rafio, Multi-room, Spotify Connect, UPnP
Stars: ✭ 151 (+586.36%)
Mutual labels:  upnp
ErpNet.FP
ErpNet.FP is a light-weight cross-platform Http server facilitating printing to fiscal printers through simple JSON Api.
Stars: ✭ 75 (+240.91%)
Mutual labels:  protocol

nat-api

NPM Version Build Status Dependency Status Standard - Javascript Style Guide

Fast port mapping with UPnP and NAT-PMP in NodeJS.

Install

Required: NodeJS >= 10

npm install nat-api

Usage

const NatAPI = require('nat-api')

const client = new NatAPI()

// Map public port 1000 to private port 1000 with UDP and TCP
client.map(1000, function (err) {
  if (err) return console.log('Error', err)
  console.log('Port mapped!')
})

// Map public port 2000 to private port 3000 with UDP and TCP
client.map(2000, 3000, function (err) {
  if (err) return console.log('Error', err)
  console.log('Port mapped!')
})

// Map public port 4000 to private port 5000 with only UDP
client.map({ publicPort: 4000, privatePort: 5000, ttl: 1800, protocol: 'UDP' }, function (err) {
  if (err) return console.log('Error', err)
  console.log('Port mapped!')
})

// Unmap port public and private port 1000 with UDP and TCP
client.unmap(1000, function (err) {
  if (err) return console.log('Error', err)
  console.log('Port unmapped!') 
})

// Get external IP
client.externalIp(function(err, ip) {
  if (err) return console.log('Error', err)
  console.log('External IP:', ip)
})

// Destroy object
client.destroy()

API

client = new NatAPI([opts])

Create a new nat-api instance.

If opts is specified, then the default options (shown below) will be overridden.

{
  ttl: 1200, // Time to live of each port mapping in seconds (default: 1200)
  autoUpdate: true, // Refresh all the port mapping to keep them from expiring (default: true)
  gateway: '192.168.1.1', // Default gateway (default: null)
  enablePMP: false // Enable PMP (default: false)
}

If gateway is not set, then nat-api will get the default gateway based on the current network interface.

client.map(port, [callback])

  • port: Public and private ports
  • callback

This method will use port por mapping the public port to the same private port.

It uses the default TTL and creates a map for UDP and TCP.

client.map(publicPort, privatePort, [callback])

  • publicPort: Public port
  • privatePort: Private port
  • callback

This is another quick way of mapping publciPort to privatePort with any protocol (UDP and TCP).

client.map(opts, [callback])

  • opts:
  • publicPort: Public port
  • privatePort: Private port
  • protocol: Port protocol (UDP, TCP or null for both)
  • ttl: Overwrite the default TTL in seconds.
  • description: Description of the port mapping
  • callback

client.unmap(port, [callback])

Unmap any port that has the public port or private port equal to port.

client.unmap(publicPort, privatePort, [callback])

Unmap any port that has the public port or private port equal to publicPort and privatePort, respectively.

client.unmap(opts, [callback])

Unmap any port that contains the parameters provided in opts.

client.externalIp([callback])

  • callback(err, ip)

Get the external IP address.

client.destroy([callback])

Destroy the client. Unmaps all the ports open with nat-api and cleans up large data structure resources.

Additional Information

License

MIT. Copyright (c) Alex

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].