Skip to content

Instantly share code, notes, and snippets.

@mgttt
Last active February 22, 2020 07:17
Show Gist options
  • Save mgttt/56974fb371405afaaf160680f80fe09f to your computer and use it in GitHub Desktop.
Save mgttt/56974fb371405afaaf160680f80fe09f to your computer and use it in GitHub Desktop.
simple port2port mapping
const argv2o=a=>(a||process.argv||[]).reduce((r,e)=>((m=e.match(/^(\/|--?)([\w-]*)="?(.*)"?$/))&&(r[m[2]]=m[3]),r),{});
const argo = argv2o();
const net = require('net');
net.createServer(from=>{
var to = net.createConnection({host:argo.to_host,port:argo.to_port});
from.pipe(to).on('error',err=>console.log('from/to',err));
to.pipe(from).on('error',err=>console.log('to/from',err));
}).on('error',err=>console.log(err)).listen(argo.from_port,argo.from_host||'0.0.0.0');
@mgttt
Copy link
Author

mgttt commented Feb 22, 2020

node proxy /to_host= /to_port= /from_port

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment