/reverseproxy

Reverse Proxy Debug Server

Primary LanguageGo

Reverse Proxy Debug Server

介绍

TCP 反向代理服务器,监听本地端口,并将请求全部转发到远端, 并将接收到的请求和远端的响应在标准输出中打印出来,方便做网络开发调试

可以用来做任何 TCP 连接的反向代理调试,抓包.

范例

HTTP 反向代理

 # bin/reverse -l localhost:9000 -r 19.45.79.21:80

 # curl -vvv http://localhost:9000/

1: 127.0.0.1:9000 .-> 127.0.0.1:59627
.................................
00000000  47 45 54 20 2f 73 74 64  6c 69 62 2d 31 2e 39 2e  |GET /stdlib-1.9.|
00000010  33 2f 6c 69 62 64 6f 63  2f 73 6f 63 6b 65 74 2f  |3/libdoc/socket/|
00000020  72 64 6f 63 2f 54 43 50  53 65 72 76 65 72 2e 68  |rdoc/TCPServer.h|
00000030  74 6d 6c e2 80 8e 20 48  54 54 50 2f 31 2e 31 0d  |tml... HTTP/1.1.|
00000040  0a 55 73 65 72 2d 41 67  65 6e 74 3a 20 63 75 72  |.User-Agent: cur|
00000050  6c 2f 37 2e 33 30 2e 30  0d 0a 48 6f 73 74 3a 20  |l/7.30.0..Host: |
00000060  31 32 37 2e 30 2e 30 2e  31 3a 39 30 30 30 0d 0a  |127.0.0.1:9000..|
00000070  41 63 63 65 70 74 3a 20  2a 2f 2a 0d 0a 0d 0a     |Accept: */*....|

<<<<<<<<<
00000000  48 54 54 50 2f 31 2e 31  20 34 30 34 20 4e 6f 74  |HTTP/1.1 404 Not|
00000010  20 46 6f 75 6e 64 0d 0a  53 65 72 76 65 72 3a 20  | Found..Server: |
00000020  6e 67 69 6e 78 0d 0a 44  61 74 65 3a 20 54 68 75  |nginx..Date: Thu|
00000030  2c 20 32 34 20 41 70 72  20 32 30 31 34 20 30 33  |, 24 Apr 2014 03|
00000040  3a 31 38 3a 34 33 20 47  4d 54 0d 0a 43 6f 6e 74  |:18:43 GMT..Cont|
...........................
00000460  3c 2f 62 6f 64 79 3e 0a  3c 2f 68 74 6d 6c 3e     |./body>../html>|

PostgreSQL 反向代理

 # bin/reverse -l localhost:9000 -r pgsql:5432
 # psql -Upgsql -h localhost -p 9000 template1


1: 127.0.0.1:9000 <-> 127.0.0.1:62851
LOCAL<<<<<
00000000  00 00 00 08 04 d2 16 2f                           |......./|
REMOTE>>>>>
00000000  53                                                |S|
LOCAL<<<<<
00000000  16 03 01 00 5f 01 00 00  5b 03 01 53 58 d7 8e c8  |...._...[..SX...|
00000010  93 3b 0a 3d e9 b4 44 f5  0a 48 ae b4 82 8f 7f 8f  |.;.=..D..H......|
00000020  4c 13 52 10 c1 25 15 2c  e9 aa 06 00 00 2e 00 39  |L.R..%.,.......9|
00000030  00 38 00 35 00 16 00 13  00 0a 00 33 00 32 00 2f  |.8.5.......3.2./|
00000040  00 9a 00 99 00 96 00 05  00 04 00 15 00 12 00 09  |................|
00000050  00 14 00 11 00 08 00 06  00 03 00 ff 01 00 00 04  |................|
00000060  00 23 00 00                                       |.#..|
REMOTE>>>>>
00000000  16 03 01 00 35 02 00 00  31 03 01 53 58 d7 3c 17  |....5...1..SX...|
00000010  22 e0 60 92 0b 91 da 38  95 ba 44 af 68 2d 6b ea  |".`....8..D.h-k.|
00000020  76 9c c8 5a 9d 64 4e 8a  69 72 17 00 00 39 00 00  |v..Z.dN.ir...9..|
00000030  09 ff 01 00 01 00 00 23  00 00 16 03 01 02 be 0b  |.......#........|
00000040  00 02 ba 00 02 b7 00 02  b4 30 82 02 b0 30 82 01  |.........0...0..|
00000050  98 a0 03 02 01 02 02 09  00 8f 8a 90 2b f0 a5 63  |............+..c|
00000060  e0 30 0d 06 09 2a 86 48  86 f7 0d 01 01 05 05 00  |.0...*.H........|
00000070  30 10 31 0e 30 0c 06 03  55 04 03 13 05 73 6c 33  |0.1.0...U....sl3|
00000080  30 30 30 1e 17 0d 31 34  30 32 32 36 30 30 30 37  |000...1402260007|

.............................................

SSH反向代理