NAT

所属分类:微信小程序
开发工具:Java
文件大小:0KB
下载次数:0
上传日期:2022-06-17 02:55:52
上 传 者sh-1993
说明:  内网穿透(1. 微 信 、支付宝支付 2. 小程序应用 3. 个人网站 ......)
(Intranet penetration (1. WeChat, Alipay 2 Applet application 3 Personal website...))

文件列表:
.idea/ (0, 2020-09-25)
.idea/NAT.iml (80, 2020-09-25)
.idea/compiler.xml (605, 2020-09-25)
.idea/jarRepositories.xml (1065, 2020-09-25)
.idea/misc.xml (616, 2020-09-25)
.idea/vcs.xml (219, 2020-09-25)
docs/ (0, 2020-09-25)
docs/flow.png (42999, 2020-09-25)
nat-client/ (0, 2020-09-25)
nat-client/dependency-reduced-pom.xml (1059, 2020-09-25)
nat-client/pom.xml (1729, 2020-09-25)
nat-client/src/ (0, 2020-09-25)
nat-client/src/main/ (0, 2020-09-25)
nat-client/src/main/java/ (0, 2020-09-25)
nat-client/src/main/java/com/ (0, 2020-09-25)
nat-client/src/main/java/com/zzz/ (0, 2020-09-25)
nat-client/src/main/java/com/zzz/nat/ (0, 2020-09-25)
nat-client/src/main/java/com/zzz/nat/client/ (0, 2020-09-25)
nat-client/src/main/java/com/zzz/nat/client/MainForm.java (7121, 2020-09-25)
nat-client/src/main/java/com/zzz/nat/client/handler/ (0, 2020-09-25)
nat-client/src/main/java/com/zzz/nat/client/handler/ClientHandler.java (5206, 2020-09-25)
nat-client/src/main/java/com/zzz/nat/client/handler/LocalProxyHandler.java (1815, 2020-09-25)
nat-client/src/main/java/com/zzz/nat/client/net/ (0, 2020-09-25)
nat-client/src/main/java/com/zzz/nat/client/net/TcpClient.java (1226, 2020-09-25)
nat-client/src/main/resources/ (0, 2020-09-25)
nat-client/src/main/resources/icon.png (3323, 2020-09-25)
nat-client/src/main/resources/log4j.properties (656, 2020-09-25)
nat-common/ (0, 2020-09-25)
nat-common/pom.xml (492, 2020-09-25)
nat-common/src/ (0, 2020-09-25)
nat-common/src/main/ (0, 2020-09-25)
nat-common/src/main/java/ (0, 2020-09-25)
nat-common/src/main/java/com/ (0, 2020-09-25)
nat-common/src/main/java/com/zzz/ (0, 2020-09-25)
nat-common/src/main/java/com/zzz/nat/ (0, 2020-09-25)
nat-common/src/main/java/com/zzz/nat/common/ (0, 2020-09-25)
nat-common/src/main/java/com/zzz/nat/common/codec/ (0, 2020-09-25)
nat-common/src/main/java/com/zzz/nat/common/codec/MessageDecoder.java (1300, 2020-09-25)
... ...

# 内网穿透 ![alt text](https://github.com/zhangbincheng1997/NAT/blob/master/docs/flow.png) ## 启动 1. java -jar nat-server.jar [port, defalut 8888] 2. java -jar nat-client.jar ## 规则(示例) 1. 外网地址:http://www.littleredhat1997.com/ 2. 内网地址:127.0.0.1 3. http://www.littleredhat1997.com:10000/ <=> 127.0.0.1:8080 | 机器 | 标识 | 端口(默认) | | :---: | :---: | :---: | | 外网代理 | Remote | 10000 | | 服务端 | Server | 8888 | | 客户端 | Client | - | | 内网代理 | Local | 8080 | ## 自定义协议 `消息体` = `消息体总长度` + `TYPE` + `length(CHANNEL_ID)` + `CHANNEL_ID` + `length(DATA)` + `DATA` ``` private MessageType type; private String channelId; private byte[] data; UNKNOWN(0), REGISTER(1), REGISTER_SUCCESS(2), REGISTER_FAILURE(3), CONNECTED(4), DISCONNECTED(5), DATA(6), KEEPALIVE(7); ``` ## 拆包粘包 LengthFieldBasedFrameDecoder Parameters: 1. maxFrameLength - the maximum length of the frame. If the length of the frame is greater than this value, TooLongFrameException will be thrown. 2. lengthFieldOffset - the offset of the length field 3. lengthFieldLength - the length of the length field 4. lengthAdjustment - the compensation value to add to the value of the length field 5. initialBytesToStrip - the number of first bytes to strip out from the decoded frame 示例: ``` new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4) public class MessageEncoder extends MessageToByteEncoder { @Override protected void encode(ChannelHandlerContext ctx, Message msg, ByteBuf out) throws Exception { // TODO } } public class MessageDecoder extends ByteToMessageDecoder { @Override protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List out) throws Exception { // TODO } } ``` ## 心跳检测 IdleStateHandler Parameters: 1. readerIdleTimeSeconds - an IdleStateEvent whose state is IdleState.READER_IDLE will be triggered when no read was performed for the specified period of time. Specify 0 to disable. 2. writerIdleTimeSeconds - an IdleStateEvent whose state is IdleState.WRITER_IDLE will be triggered when no write was performed for the specified period of time. Specify 0 to disable. 3. allIdleTimeSeconds - an IdleStateEvent whose state is IdleState.ALL_IDLE will be triggered when neither read nor write was performed for the specified period of time. Specify 0 to disable. 示例: ``` new IdleStateHandler(60, 30, 0) @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof IdleStateEvent) { IdleStateEvent e = (IdleStateEvent) evt; if (e.state() == IdleState.READER_IDLE) { // TODO } else if (e.state() == IdleState.WRITER_IDLE) { // TODO } else if (e.state() == IdleState.ALL_IDLE) { // TODO } } } ```
近期下载者

相关文件


收藏者