upnpjs
v1.1.1
Published
A Node.js package for using UPnP
Downloads
32
Maintainers
Readme
UPnP Node.js Package
Node.js package built for managing a router using UPnP.
Installation
Install upnpjs Library
npm install upnpjs
Install upnp CLI
# Use `upnp -h` to show help menu
npm install upnpjs -g
Getting Started
Discover the Internet Gateway Device
const upnp = require('upnpjs');
const igd = await upnp.discover();
InternetGatewayDevice
InternetGatewayDevice allows access to different services potentially allowed by the device
addPortMapping
Service action for mapping ports on the router
await igd.addPortMapping({
ip: 192.168.0.4,
internalPort: 54321,
externalPort: 54321,
protocol: 'TCP', // Defaults to TCP
description: 'Example port map from 54321 -> 54321', // Defaults to empty string
enabled: false // Defaults to true
});
deletePortMapping
Service action for removing port mappings on the router
await igd.deletePortMapping({
externalPort: 12345,
protocol: 'UDP'
});
getExternalIPAddress
Service action for retrieving external ip address
const ip = await igd.getExternalIPAddress();
getPortMappingList
Service action for listing all currently mapped ports on the router
const list = await igd.getPortMappingList();
getPortMapping
Service action for remtrieving a single port map by index
const portmap = await igd.getPortMapping(2);
References
Documents
UPnP Architecture | Service Template | UPnP Background | Internet Gateway Device
Code Samples
miniupnp | TinyUPnP | weupnp | upnpclient | Node.js and SSDP