@nickreynolds2/nat-port-mapper
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

@nickreynolds/nat-port-mapper

Build Status Coverage Status

Fast port mapping with UPnP and NAT-PMP in NodeJS

Install

npm install nat-api

Usage

import { upnpNat } from '@achingbrain/nat-port-mapper'

const client = await upnpNat({
  // all fields are optional
  ttl: number // how long mappings should live for in seconds - min 20 minutes, default 2 hours
  description: string // default description to pass to the router for a mapped port
  gateway: string // override the router address, will be auto-detected if not set
  keepAlive: boolean // if true, refresh the mapping ten minutes before the ttl is reached, default true
})

// Map public port 1000 to private port 1000 with TCP
await client.map({
  localPort: 1000,
  protocol: 'TCP'
})

// Map public port 2000 to private port 3000 with UDP
await client.map({
  publicPort: 2000,
  localPort: 3000,
  protocol: 'UDP'
})

// Unmap port public and private port 1000 with TCP
await client.unmap({
  localPort: 1000,
  protocol: 'TCP'
})

// Get external IP
const externalIp = await client.externalIp()

console.log('External IP:', ip)

// Unmap all mapped ports
client.close()

Credits

Based on alxhotel/nat-api Forked from @achingbrain/nat-port-matter

Additional Information

Purpose of this repo is to figure out why can't include @achingbrain/nat-port-mapper (and other packages build with aegir) in Jest tests

License

Apache-2.0 or MIT

Package Sidebar

Install

npm i @nickreynolds2/nat-port-mapper

Weekly Downloads

1

Version

1.0.3

License

Apache-2.0 OR MIT

Unpacked Size

111 kB

Total Files

38

Last publish

Collaborators

  • nickreynolds2