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

2.0.5 • Public • Published

@achingbrain/nat-port-mapper

codecov CI

Port mapping with UPnP and NAT-PMP

About

Example

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(1000, {
  protocol: 'TCP'
})

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

// Unmap previously mapped private port 1000
await client.unmap(1000)

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

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

// Unmap all mapped ports
await client.close()

Credits

Based on alxhotel/nat-api

Additional Information

Install

$ npm i @achingbrain/nat-port-mapper

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Package Sidebar

Install

npm i @achingbrain/nat-port-mapper

Weekly Downloads

5,726

Version

2.0.5

License

Apache-2.0 OR MIT

Unpacked Size

120 kB

Total Files

49

Last publish

Collaborators

  • achingbrain