2.0.4 • Published 8 months ago
@achingbrain/nat-port-mapper v2.0.4
@achingbrain/nat-port-mapper
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
- http://miniupnp.free.fr/nat-pmp.html
- http://wikipedia.org/wiki/NAT_Port_Mapping_Protocol
- http://tools.ietf.org/html/draft-cheshire-nat-pmp-03
Install
$ npm i @achingbrain/nat-port-mapper
License
Licensed under either of
- Apache 2.0, (LICENSE-APACHE / http://www.apache.org/licenses/LICENSE-2.0)
- MIT (LICENSE-MIT / http://opensource.org/licenses/MIT)
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.18
8 months ago
1.0.17
8 months ago
1.0.16
8 months ago
2.0.3
8 months ago
2.0.2
8 months ago
2.0.4
8 months ago
2.0.1
8 months ago
2.0.0
8 months ago
1.0.15
9 months ago
1.0.14
9 months ago
1.0.13
2 years ago
1.0.11
2 years ago
1.0.10
2 years ago
1.0.12
2 years ago
1.0.9
2 years ago
1.0.8
2 years ago
1.0.7
3 years ago
1.0.6
3 years ago
1.0.2
3 years ago
1.0.5
3 years ago
1.0.4
3 years ago
1.0.3
3 years ago
1.0.1
3 years ago
1.0.0
3 years ago
0.0.0
3 years ago