Skip to content

yinheli/tcpproxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

#一个简单 tcp 代理服务

##用途 这个小工具主要是用来调试 pos: (当然也可以其他)

##场景: pos 冲正测试, 需要模拟网络超时 查看 pos 机发送的原始报文(16进制)

正对上述两种测试场景, 我们公司研发/测试部门的同事门, 采用的是如下方式:

掐算好时间, 拔掉电池 
用网卡抓包的方式 

以上, 粗鲁的 方式确实能解决问题. 但是非常不方便.

##使用 这个小工具使用非常简单.

[appuser@pos-dev ~]$ tcpproxy 

  tcpproxy v1.0.2  @author yinheli
Usage of tcpproxy:
  -debug
    	print debug message
  -format hex
    	debug output format, hex or `string` (default "hex")
  -port string
    	listen port, default 1234 (default "1234")
  -sleep int
    	every transfer with sleep second(s)
  -sleepLoc string
    	sleep position, before: before send to backend server; after: after receive data from backend; both: all (default "after")
  -target string
    	target host and port. eg: 192.168.1.100:9001
  -timeout int
    	timeout (second), default 60s (default 60)

update to v1.0.2 add format option

一个 pos 签到的例子, 如果要测试超时, 可以添加 sleep 参数即可, 然后在收到后端 posp 的响应后 ctrl + c 关掉代理, 不给 pos 响应.

[appuser@pos-dev ~]$ tcpproxy -port=52100 -target=192.168.1.52:4007 -debug=true

  tcpproxy v1.0.1  @author yinheli
  **********

2014/08/01 20:27:42 start proxy: listen:52100, target:192.168.1.52:4007, timeout:60, debug:true, sleep:0, sleepLoc:after
2014/08/01 20:27:48 start: 117.136.0.61:37307 <-> 192.168.1.52:4007
2014/08/01 20:27:48 send: 117.136.0.61:37307 <-> 192.168.1.52:4007, time:319ms 
00000000  00 da 60 00 06 00 00 60  31 00 31 10 03 08 00 00  |..`....`1.1.....|
00000010  20 00 00 00 c0 00 d6 00  04 63 33 30 30 30 38 37  | ........c300087|
00000020  38 38 5a 30 33 30 30 30  30 30 30 30 30 38 31 36  |88Z0300000000816|
00000030  35 00 09 56 31 2e 34 7c  56 31 2e 34 01 18 34 36  |5..V1.4|V1.4..46|
00000040  30 2c 30 30 2c 31 31 33  42 2c 35 36 32 46 2c 34  |0,00,113B,562F,4|
00000050  36 30 2c 30 30 2c 31 30  32 43 2c 32 37 46 45 2c  |60,00,102C,27FE,|
00000060  34 36 30 2c 30 30 2c 31  30 32 43 2c 32 37 46 44  |460,00,102C,27FD|
00000070  2c 34 36 30 2c 30 30 2c  31 30 32 43 2c 30 30 30  |,460,00,102C,000|
00000080  30 2c 34 36 30 2c 30 30  2c 31 30 32 43 2c 42 32  |0,460,00,102C,B2|
00000090  34 37 2c 34 36 30 2c 30  30 2c 31 31 33 42 2c 32  |47,460,00,113B,2|
000000a0  41 43 32 2c 34 36 30 2c  30 30 2c 30 30 30 30 2c  |AC2,460,00,0000,|
000000b0  30 30 30 30 00 11 00 00  00 02 00 10 00 25 53 65  |0000.........%Se|
000000c0  71 75 65 6e 63 65 20 4e  6f 31 32 33 31 31 36 30  |quence No1231160|
000000d0  32 30 38 34 35 31 37 00  03 30 31 20              |2084517..01 |

2014/08/01 20:27:48 recive: 192.168.1.52:4007 <-> 117.136.0.61:37307, time:361ms 
00000000  00 d3 60 00 00 00 06 60  31 00 31 10 03 08 10 00  |..`....`1.1.....|
00000010  38 00 00 02 c1 00 16 00  04 63 20 27 48 08 01 30  |8........c 'H..0|
00000020  30 33 30 30 30 38 37 38  38 5a 30 33 30 30 30 30  |030008788Z030000|
00000030  30 30 30 30 38 31 36 35  01 16 43 30 31 35 5a 30  |00008165..C015Z0|
00000040  33 30 30 30 30 30 30 30  30 38 31 36 35 43 31 30  |3000000008165C10|
00000050  38 d6 d0 2a 2a 2a 2a 2a  2a 43 32 31 30 46 46 46  |8..******C210FFF|
00000060  46 46 46 46 46 46 46 43  33 30 33 30 30 30 43 34  |FFFFFFFC303000C4|
00000070  30 31 31 43 35 30 31 31  43 36 30 32 31 31 43 37  |011C5011C60211C7|
00000080  31 39 cb e6 d0 e8 b6 f8  d6 c1 20 2d 20 ca d5 b8  |19........ - ...|
00000090  b6 d7 d4 c8 e7 43 38 31  35 30 32 32 20 2d 20 32  |.....C815022 - 2|
000000a0  36 32 38 20 33 33 36 36  43 39 30 32 31 31 00 11  |628 3366C90211..|
000000b0  00 00 00 02 00 10 00 24  c4 f5 17 ac 93 4e 2f 71  |.......$.....N/q|
000000c0  c3 6c 53 05 0e 31 d0 9b  5c e1 04 99 9b 60 9f 4d  |.lS..1..\....`.M|
000000d0  00 03 30 31 20                                    |..01 |

2014/08/01 20:27:49 end: 117.136.0.61:37307 <-> 192.168.1.52:4007, time:819ms
-----

##最后希望这个工具也能帮到你.

如果你懒的手动编译, 我这里在 centos 64 位下编译了一个版本. 下载地址: http://pan.baidu.com/s/1o6wRCpG