{"name":"@achingbrain/nat-port-mapper","version":"2.0.0","keywords":["api","forwarding","holepunch","map","mapping","nat","nat-pmp","pmp","port","upnp"],"license":"Apache-2.0 OR MIT","_id":"@achingbrain/nat-port-mapper@2.0.0","maintainers":[{"name":"achingbrain","email":"alex@achingbrain.net"}],"homepage":"https://github.com/achingbrain/nat-port-mapper#readme","bugs":{"url":"https://github.com/achingbrain/nat-port-mapper/issues"},"dist":{"shasum":"d68f1a739501ba02eb4eca6a728438c5f60d1744","tarball":"http://registry-npm.ywwl.com/@achingbrain/nat-port-mapper/download/@achingbrain/nat-port-mapper-2.0.0.tgz","fileCount":44,"integrity":"sha512-R47FQ0c0IQyczgTA+Q7X7x/0gJvRToq3FK/ukKZ27xdGTPsoK41xT5EOJQVkkNUQuu/+HHtUV8gSjOFSwqMiQw==","signatures":[{"sig":"MEQCIHS1wDZY/Qr8pqxICBGSFW7St0hbCTE1oe4CDnlZsBL0AiAzvQa9ZQ49N0gA4nW0KsObdU1+/CKbxZiu8wYAcfaC8w==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@achingbrain%2fnat-port-mapper@2.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":117286,"size":27034,"noattachment":false,"key":"/@achingbrain/nat-port-mapper/-/@achingbrain/nat-port-mapper-2.0.0.tgz"},"type":"module","types":"./dist/src/index.d.ts","exports":{".":{"types":"./dist/src/index.d.ts","import":"./dist/src/index.js","browser":"./dist/src/browser.js"}},"gitHead":"6c5a5e4abfb8248e2c6d2533812f81ea765b66a1","release":{"plugins":[["@semantic-release/commit-analyzer",{"preset":"conventionalcommits","releaseRules":[{"release":"major","breaking":true},{"revert":true,"release":"patch"},{"type":"feat","release":"minor"},{"type":"fix","release":"patch"},{"type":"docs","release":"patch"},{"type":"test","release":"patch"},{"type":"deps","release":"patch"},{"scope":"no-release","release":false}]}],["@semantic-release/release-notes-generator",{"preset":"conventionalcommits","presetConfig":{"types":[{"type":"feat","section":"Features"},{"type":"fix","section":"Bug Fixes"},{"type":"chore","section":"Trivial Changes"},{"type":"docs","section":"Documentation"},{"type":"deps","section":"Dependencies"},{"type":"test","section":"Tests"}]}}],"@semantic-release/changelog","@semantic-release/npm","@semantic-release/github","@semantic-release/git"],"branches":["main"]},"scripts":{"docs":"aegir docs","lint":"aegir lint","test":"aegir test -t node","build":"aegir build --no-bundle","clean":"aegir clean","release":"aegir release","dep-check":"aegir dep-check","test:node":"aegir test -t node"},"_npmUser":{"name":"achingbrain","email":"alex@achingbrain.net"},"repository":{"url":"git+https://github.com/achingbrain/nat-port-mapper.git","type":"git"},"_npmVersion":"10.9.0","description":"Port mapping with UPnP and NAT-PMP","directories":{},"_nodeVersion":"20.18.0","dependencies":{"xml2js":"^0.6.0","p-defer":"^4.0.0","err-code":"^3.0.1","it-first":"^3.0.1","any-signal":"^4.1.1","abort-error":"^1.0.0","race-signal":"^1.1.0","@libp2p/logger":"^5.0.1","default-gateway":"^7.2.2","@achingbrain/ssdp":"^4.1.0"},"eslintConfig":{"extends":"ipfs","parserOptions":{"project":true,"sourceType":"module"}},"publishConfig":{"access":"public","provenance":true},"_hasShrinkwrap":false,"devDependencies":{"aegir":"^45.0.1","@types/xml2js":"^0.4.11","@types/default-gateway":"^7.2.0"},"_npmOperationalInternal":{"tmp":"tmp/nat-port-mapper_2.0.0_1730483147697_0.9310531439502132","host":"s3://npm-registry-packages"},"readme":"# @achingbrain/nat-port-mapper\n\n[![codecov](https://img.shields.io/codecov/c/github/achingbrain/nat-port-mapper.svg?style=flat-square)](https://codecov.io/gh/achingbrain/nat-port-mapper)\n[![CI](https://img.shields.io/github/actions/workflow/status/achingbrain/nat-port-mapper/js-test-and-release.yml?branch=main\\&style=flat-square)](https://github.com/achingbrain/nat-port-mapper/actions/workflows/js-test-and-release.yml?query=branch%3Amain)\n\n> Port mapping with UPnP and NAT-PMP\n\n# About\n\n<!--\n\n!IMPORTANT!\n\nEverything in this README between \"# About\" and \"# Install\" is automatically\ngenerated and will be overwritten the next time the doc generator is run.\n\nTo make changes to this section, please update the @packageDocumentation section\nof src/index.js or src/index.ts\n\nTo experiment with formatting, please run \"npm run docs\" from the root of this\nrepo and examine the changes made.\n\n-->\n\nEnable NAT traversal by mapping public ports to ports on your computer using\neither [UPnP](https://en.wikipedia.org/wiki/Universal_Plug_and_Play) or\n[NAT-PMP](https://en.wikipedia.org/wiki/NAT_Port_Mapping_Protocol).\n\n## Example - UPnP NAT\n\n```TypeScript\nimport { upnpNat } from '@achingbrain/nat-port-mapper'\n\nconst client = upnpNat()\n\nfor await (const gateway of client.findGateways({ signal: AbortSignal.timeout(10000) })) {\n  // Map public port 1000 to private port 1000 with TCP\n  await gateway.map(1000, '192.168.1.123', {\n    protocol: 'tcp'\n  })\n\n  // Map port 3000 to any available host name\n  for await (const mapping of gateway.mapAll(3000, {\n    protocol: 'udp'\n  })) {\n    console.info(`mapped ${mapping.internalHost}:${mapping.internalPort} to ${mapping.externalHost}:${mapping.externalPort}`)\n  }\n\n  // Unmap previously mapped private port 1000\n  await gateway.unmap(1000)\n\n  // Get external IP\n  const externalIp = await gateway.externalIp()\n\n  console.log('External IP:', externalIp)\n\n  // Unmap all mapped ports and cancel any in-flight network operations\n  await gateway.stop()\n}\n```\n\n## Example - NAT-PMP\n\n```TypeScript\nimport { pmpNat } from '@achingbrain/nat-port-mapper'\nimport { gateway4sync } from 'default-gateway'\n\nconst gateway = pmpNat(gateway4sync().gateway)\n\n// Map public port 1000 to private port 1000 with TCP\nawait gateway.map(1000, '192.168.1.123', {\n  protocol: 'tcp'\n})\n\n// Map public port 2000 to private port 3000 with UDP\nawait gateway.map(3000, '192.168.1.123', {\n  externalPort: 2000,\n  protocol: 'udp'\n})\n\n// Unmap previously mapped private port 1000\nawait gateway.unmap(1000)\n\n// Get external IP\nconst externalIp = await gateway.externalIp()\n\nconsole.log('External IP:', externalIp)\n\n// Unmap all mapped ports and cancel any in-flight network operations\nawait gateway.stop()\n```\n\n## Credits\n\nBased on [alxhotel/nat-api](https://github.com/alxhotel/nat-api)\n\n## Additional Information\n\n- <http://miniupnp.free.fr/nat-pmp.html>\n- <http://wikipedia.org/wiki/NAT_Port_Mapping_Protocol>\n- <http://tools.ietf.org/html/draft-cheshire-nat-pmp-03>\n\n# Install\n\n```console\n$ npm i @achingbrain/nat-port-mapper\n```\n\n# API Docs\n\n- <https://achingbrain.github.io/nat-port-mapper>\n\n# License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](https://github.com/achingbrain/nat-port-mapper/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)\n- MIT ([LICENSE-MIT](https://github.com/achingbrain/nat-port-mapper/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)\n\n# Contribution\n\nUnless 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.\n","publish_time":1730483147941,"_cnpm_publish_time":1730483147941,"dist-tags":{"latest":"4.0.5"}}