Giter Site home page Giter Site logo

socket-pipe's Introduction

Socket Pipe

Socket Pipe can forward your socket from one address to anoter without any configs. It supports both tcp and udp, you can simplely make a software net-bridge.

Install

npm install -g socket-pipe

Usage

Tcp socket forwarding

The following example shows how to map a remote address (ip=192.168.1.100 port=80) to a local address (ip=127.0.0.1 port=80) via tcp tunnel.

socket-pipe -l 127.0.0.1@80 -r 192.168.1.100@80 -t tcp

Udp socket forwarding

The following example shows how to map a remote address (ip=8.8.8.8 port=53) to a local address (ip=127.0.0.1 port=53) via udp tunnel.

socket-pipe -l 127.0.0.1@53 -r 8.8.8.8@53 -t udp

Tcp reverse tunnel

The following example shows how to map a server from LAN (ip=192.168.1.100 port=80) to internet (ip=123.123.123.123 port=80).

Client side (LAN)

socket-pipe -l 192.168.1.100@80 -r 123.123.123.123@10080 -t tclient

Server side (internet)

socket-pipe -l 123.123.123.123@10080 -r 123.123.123.123@80 -t tserver

Http reverse tunnel

The following example shows how to map multi http servers from LAN (ip=[192.168.1.100 - 192.168.1.102] port=80) to internet (ip=123.123.123.123 port=80).

Client side (LAN)

http1

socket-pipe -l 192.168.1.100@80 -r 123.123.123.123@10080 -t hclient -x git.dev.com -s git

http2

socket-pipe -l 192.168.1.101@80 -r 123.123.123.123@10080 -t hclient -x file.dev.com

http3

socket-pipe -l 192.168.1.102@80 -r 123.123.123.123@10080 -t hclient -s wiki

Server side (internet)

socket-pipe -l 123.123.123.123@10080 -r 123.123.123.123@80 -t hserver

There are two special params.

  1. -x means socket-pipe will transform:
    1. The Host value in http request header.
    2. The host part of 'Location' value in http response header.
  2. -s means specify a domain prefix. The server side will create a random prefix without specifying.

Now you can visit different backend http server in a LAN from a portal on internet.

For example if domain *.test.com is pointing to 123.123.123.123, the visits to http://git.test.com/ will be forwarded to http://192.168.1.100/ with host git.dev.com because of the domain prefix git.

socket-pipe's People

Contributors

joyqi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

socket-pipe's Issues

Error:listen EADDRNOTAVAIL

C:\Users\Administrator>socket-pipe -l 123.206.58.202@18888 -r 123.206.58.202@808
0 -t tserver
Piping 123.206.58.202@18888 to 123.206.58.202@8080 via tserver
{ Error: listen EADDRNOTAVAIL 123.206.58.202:18888
    at Object._errnoException (util.js:1021:11)
    at _exceptionWithHostPort (util.js:1043:20)
    at Server.setupListenHandle [as _listen2] (net.js:1327:19)
    at listenInCluster (net.js:1385:12)
    at doListen (net.js:1494:7)
    at _combinedTickCallback (internal/process/next_tick.js:141:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
    at Function.Module.runMain (module.js:667:11)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
  code: 'EADDRNOTAVAIL',
  errno: 'EADDRNOTAVAIL',
  syscall: 'listen',
  address: '123.206.58.202',
  port: 18888 }
{ Error: listen EADDRNOTAVAIL 123.206.58.202:8080
    at Object._errnoException (util.js:1021:11)
    at _exceptionWithHostPort (util.js:1043:20)
    at Server.setupListenHandle [as _listen2] (net.js:1327:19)
    at listenInCluster (net.js:1385:12)
    at doListen (net.js:1494:7)
    at _combinedTickCallback (internal/process/next_tick.js:141:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
    at Function.Module.runMain (module.js:667:11)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
  code: 'EADDRNOTAVAIL',
  errno: 'EADDRNOTAVAIL',
  syscall: 'listen',
  address: '123.206.58.202',
  port: 8080 }

服务器用的是腾讯云的。

关于端口转发的问题

# 如果服务端启动命令为
socket-pipe -l 10080 -r 80 -t hserver -s ng

# 客户端启动命令为
socket-pipe -l 80 -r 123.123.123.123@10080 -t hclient -s ng

此时一切正常, 我可以通过访问 ng.domain.com 访问本机

# 修改服务端命令
socket-pipe -l 10080 -r 8080 -t hserver -s ng

客户端启动命令为
socket-pipe -l 80 -r 123.123.123.123@10080 -t hclient -s ng

此时访问ng.domain.com出错,
访问 ng.domain.com:8080 正常 可以访问本机

请问能否做到服务端代理的端口为8080 但是可以直接通过 ng.domain.com 访问本机的80端口

我现在的操作是 用了nginx 做代理

upstream ng {
    server 127.0.0.1:8080;
    keepalive 64;
}
server {
    listen 80;
    server_name *.domain.com;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host:80;
        proxy_set_header X-Nginx-Proxy true;
        proxy_set_header Connection "";
        proxy_pass http://ng;
    }
}

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.