Created
March 29, 2020 17:37
-
-
Save nondanee/f749b0b1122ac528ed4056ae4898b22a to your computer and use it in GitHub Desktop.
TCP port tunnel server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const net = require('net') | |
const local = { host: '0.0.0.0', port: 12000 } | |
const remote = { host: '127.0.0.1', port: 8080 } | |
net | |
.createServer({ allowHalfOpen: true }) | |
.listen(local) | |
.on('connection', socket => { | |
const proxySocket = net.connect(remote.port, remote.host) | |
.on('data', data => socket.write(data)) | |
.on('error', () => proxySocket.end()) | |
socket | |
.on('data', data => proxySocket.write(data)) | |
.on('error', () => socket.end()) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment