
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
@achingbrain/nat-port-mapper
Advanced tools
Port mapping with UPnP and NAT-PMP
Enable NAT traversal by mapping public ports to ports on your computer using either UPnP or NAT-PMP.
import { upnpNat } from '@achingbrain/nat-port-mapper'
const client = upnpNat()
for await (const gateway of client.findGateways({ signal: AbortSignal.timeout(10000) })) {
// Map public port 1000 to private port 1000 with TCP
await gateway.map(1000, '192.168.1.123', {
protocol: 'tcp'
})
// Map port 3000 to any available host name
for await (const mapping of gateway.mapAll(3000, {
protocol: 'udp'
})) {
console.info(`mapped ${mapping.internalHost}:${mapping.internalPort} to ${mapping.externalHost}:${mapping.externalPort}`)
}
// Unmap previously mapped private port 1000
await gateway.unmap(1000)
// Get external IP
const externalIp = await gateway.externalIp()
console.log('External IP:', externalIp)
// Unmap all mapped ports and cancel any in-flight network operations
await gateway.stop()
}
import { pmpNat } from '@achingbrain/nat-port-mapper'
import { gateway4sync } from 'default-gateway'
const gateway = pmpNat(gateway4sync().gateway)
// Map public port 1000 to private port 1000 with TCP
await gateway.map(1000, '192.168.1.123', {
protocol: 'tcp'
})
// Map public port 2000 to private port 3000 with UDP
await gateway.map(3000, '192.168.1.123', {
externalPort: 2000,
protocol: 'udp'
})
// Unmap previously mapped private port 1000
await gateway.unmap(1000)
// Get external IP
const externalIp = await gateway.externalIp()
console.log('External IP:', externalIp)
// Unmap all mapped ports and cancel any in-flight network operations
await gateway.stop()
Based on alxhotel/nat-api
$ npm i @achingbrain/nat-port-mapper
Licensed under either of
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.
FAQs
Port mapping with UPnP and NAT-PMP
The npm package @achingbrain/nat-port-mapper receives a total of 28,830 weekly downloads. As such, @achingbrain/nat-port-mapper popularity was classified as popular.
We found that @achingbrain/nat-port-mapper demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.