Socket
Socket
Sign inDemoInstall

@achingbrain/nat-port-mapper

Package Overview
Dependencies
57
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @achingbrain/nat-port-mapper

Port mapping with UPnP and NAT-PMP


Version published
Weekly downloads
7.8K
decreased by-38.86%
Maintainers
1
Install size
5.28 MB
Created
Weekly downloads
 

Changelog

Source

1.0.13 (2023-12-01)

Dependencies

  • bump @libp2p/logger from 3.1.0 to 4.0.1 (#54) (5f9092b)

Readme

Source

@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.

Keywords

FAQs

Last updated on 01 Dec 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc