Git Product home page Git Product logo

nano-tcp-relay's Introduction

Nano TCP Relay

Some times I need to relay TCP connections through some machines, and this can be achieved by nc command with a fifo file :

#!/usr/bin/sh
if [ -z $1 ] || [ -z $2 ] || [ -z $3 ]; then
    echo "Usage: $0 port host port"
    exit
fi

backpipe="backpipe-$1-$2-$3"

if [ -p $backpipe ]; then
    echo "$backpipe exists."
else
    mkfifo $backpipe
fi

while [ 1 ]; do
    echo "listening on port $1 and redirect to $2:$3"
    nc -l $1 0<$backpipe | nc $2 $3 1>$backpipe
    echo "one connection ends, start another."
done

Usage

  • Transparently relay TCP ports

    $ nano-tcp-relay {host} {port-1} [{port-2} ... {port-n}]
    
    • Works as following

      Internet ---> localhost:{port-1} ---> {host}:{port-1}
      Internet ---> localhost:{port-2} ---> {host}:{port-2}
      ...
      Internet ---> localhost:{port-n} ---> {host}:{port-n}
      
  • Port forwarding

    $ nano-tcp-relay {host} {src-port-1}-{dst-port-1} [{src-port-2}-{dst-port-2} ...]
    
    • Works as following

      Internet --> localhost:{src-port-1} ---> {host}:{dst-port-1}
      Internet --> localhost:{src-port-2} ---> {host}:{dst-port-2}
      ...
      Internet --> localhost:{src-port-n} ---> {host}:{dst-port-n}
      

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.