GithubHelp home page GithubHelp logo

gortcp's Introduction

gortcp

内网穿透,灵感来源于rtcp

使用场景:

A服务器在内网,公网无法直接访问这台服务器,但是A服务器可以联网访问公网的B服务器(假设IP为222.2.2.2)。 我们也可以访问公网的B服务器。于是我们可以利用B服务器来做端口转发。

知道创宇老杨给的那个rtcp非常精简,实现的也非常漂亮。

但每次转发都要在B服务器上运行rtcp程序并且占用两个端口,对我来说还是有点不便:)

我的想法是B服务器能不能固定两个端口用来转发,一个供内网A类服务器连接,一个供我们连接,我们可以自定义在A上连接的服务器IP和端口。

这样理论上B就可以同时hold住数以千计的转发连接(依赖于单进程能打开的最大fd数),可以将B服务器打造成一个集中的转发server。

使用方法:

1,服务器B以listen模式运行:

gortcp l 222.2.2.2:12000 222.2.2.2:13000 222.2.2.2:9898

12000端口供A服务器连接,13000端口供我们连接,9898是一个http server,下面会用到。

2,客户端A以connect模式运行:

gortcp c 222.2.2.2:12000

3,查看B服务器上已经连接的服务器:

curl http://222.2.2.2:9898/list

host1 x.x.x.x:37601
host2 y.y.y.y:11233

4,指定连接的服务器:

curl http://222.2.2.2:9898/conn?id=<x.x.x.x:37601>&addr=<localhost:22>

其中id为上面列出的IP加端口。addr通知A服务器连接这个IP和端口。
localhost:22指连接本机的22端口。 10.10.0.1:80指连接10.10.0.1的80端口。
B服务器上13000端口默认是不接受连接的,通过这一步才会接受一个连接,并将这个连接的数据转发到参数中指定的主机端口上面。

这一步算是一个妥协吧,因为固定了端口,所有需要指定转发的地址。

5,开始连接

ssh [email protected] -p 13000,这样我们就可以连接ssh服务了。
如果上面我们连接的是80端口。我们可以指浏览器中输入http://222.2.2.2:13000访问web服务。

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.