forawait (constgatewayofclient.findGateways({ signal:AbortSignal.timeout(10000) })) { // Map public port 1000 to private port 1000 with TCP awaitgateway.map(1000, '192.168.1.123', { protocol:'tcp' })
// Map port 3000 to any available host name forawait (constmappingofgateway.mapAll(3000, { protocol:'udp' })) { console.info(`mapped ${mapping.internalHost}:${mapping.internalPort} to ${mapping.externalHost}:${mapping.externalPort}`) }
// Unmap previously mapped private port 1000 awaitgateway.unmap(1000)
// Get external IP constexternalIp = awaitgateway.externalIp()
console.log('External IP:', externalIp)
// Unmap all mapped ports and cancel any in-flight network operations awaitgateway.stop() }
Enable NAT traversal by mapping public ports to ports on your computer using either UPnP or NAT-PMP.
Example: UPnP NAT
Example: NAT-PMP
Credits
Based on alxhotel/nat-api
Additional Information