npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@spurreiter/wstun

v2.0.2

Published

A set of tools to establish TCP tunnels (or TCP reverse tunnels) over WebSocket connections for circumventing the problem of directly connect to hosts behind a strict firewall or without public IP. It also supports WebSocket Secure (wss) connections.

Downloads

27

Readme

WSTUN - Tunnels and Reverse Tunnels over WebSocket

badge npm version types-badge

An improved fork of https://github.com/MDSLab/wstun.

  • Refactored to use ESM
  • Linted and Typed

Table of Contents

Overview

A set of Node.js tools to establish TCP tunnels (or TCP reverse tunnels) over WebSocket connections for circumventing the problem of directly connect to hosts behind a strict firewall or without public IP. It also supports WebSocket Secure (wss) connections.

Installation

npm install @spurreiter/wstun

Forward WS Tunnel

           host                         remote
        +--------+             +--------+      +---------+
        |  :9000 |----wstun--->|  :4000 |      |   :3000 |
   ====>| client |=====tcp====>| server |=====>| service |
:9000   |        |----wstun--->|        |      |         |
        +--------+             +--------+      +---------+

Instantiation of a forward tunnel server

import { Server } from '@spurreiter/wstun'

// start with TLS
const server = new Server({
  tlsOptions: {
    key: 'path-to-private-key',
    cert: 'path-to-public-cert'
  }
})

// listening port where websocket gets connected
const port = 4000
// destination host and port (optional)
const dstAddr = '127.0.0.1:3000'
server.start(port, dstAddr)

Implementation of a forward tunnel client

import { Client } from '@spurreiter/wstun'

const client = new Client({
  tlsOptions: {
    ca: 'path-to-public-cert' // for self signed certs
  }
})

// is the port on the localhost on which the tunneled service will be reachable
const localPort = 9000
const wsHostUrl = new URL('wss://remote:4000')

client.start(localPort, wsHostUrl)

Reverse WS Tunnel

           host                        remote
        +--------+             +--------+      +---------+
        |  :8000 |<---wstun----|        |      |   :3000 |
  =====>| server |=====tcp====>| client |=====>| service |
:9000   |        |<---wstun----|        |      |         |
        +--------+             +--------+      +---------+

Instantiation of a reverse tunnel server

import { ServerReverse } from '@spurreiter/wstun'

// start with TLS
const serverRev = new ServerReverse({
  tlsOptions: {
    key: 'path-to-private-key',
    cert: 'path-to-public-cert'
  }
})

// listening port where websocket is connected
const port = 8000
serverRev.start(port)

Implementation of a reverse tunnel client

import { ClientReverse } from '@spurreiter/wstun'

const clientRev = new ClientReverse({
  tlsOptions: {
    ca: 'path-to-public-cert' // for self signed certs
  }
})

// is the port on the localhost on which the tunneled service will be reachable
const tunnelPort = 9000
const wsHostUrl = new URL('wss://host:8000')
const remoteAddr = '127.0.0.1:3000'

clientRev.start(tunnelPort, wsHostUrl, remoteAddr)

CLI

    Tunnels and reverse tunnels over WebSocket.

    wstun [options]

    -h|--help

    -s|--server   port        run as server, specify listening port

    -r|--reverse              run server in reverse tunneling mode

    -t|--tunnel   [localport:]host:port
                              run as tunnel client, specify [localport:]host:port

    -a|--allow    file.json   server accepts only the requests coming from
                              authorized clients. Specify the path to the file
                              containing authorized clients. Must be a .json
                              file with:
                              [{id: <uuid>, destinations: [<string>]}, {..}]

    -u|--uuid     string      specify the bearer auth of the client

      |--local                tunnel server listens only on local host
                              "127.0.0.1" instead of all hosts "0.0.0.0".

      |--reconnect [number]   reconnect server or client after connection errors.
                              Optionally specify the number of ms to restart.

      |--key      filename    path to private key certificate

      |--cert     filename    path to public key certificate

      |--ca       filename    certification authority


    Examples:

    (forward tunnel server)
    wstun -t 127.0.0.1:3000 -s 4000 --key s.key --cert s.crt
    (forward tunnel client)
    wstun -t 9000 --ca s.crt wss://host:4000

    (reverse tunnel server)
    wstun -s 8000 --key s.key --cert s.crt
    (reverse tunnel client)
    wstun.js -r -t 9000:127.0.0.1:3000 --ca s.crt wss://host:8000

Logging system

wstun uses debug-level for logging.

To log to a file use, e.g.

npm i -g @spurreiter/wstun

NODE_ENV=production wstun -s 8000 2> /var/log/wstun.log