1.0.13 • Published 5 months ago

@achingbrain/nat-port-mapper v1.0.13

Weekly downloads
-
License
Apache-2.0 OR MIT
Repository
github
Last release
5 months ago

@achingbrain/nat-port-mapper

codecov CI

Port mapping with UPnP and NAT-PMP

Table of contents

Install

$ npm i @achingbrain/nat-port-mapper

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

Additional Information

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.

1.0.13

5 months ago

1.0.11

9 months ago

1.0.10

9 months ago

1.0.12

7 months ago

1.0.9

11 months ago

1.0.8

1 year ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.2

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.0

2 years ago