Last active
July 4, 2019 03:16
-
-
Save fand/3953146c535a5861ec2f182daa831004 to your computer and use it in GitHub Desktop.
Forward TCP to UDP
This file contains hidden or 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
#!/usr/bin/env node | |
const net = require('net'); | |
const dgram = require('dgram'); | |
if (process.argv.length !== 4) { | |
console.error(` | |
Usage: | |
node tcp2udp.js <TCP_SRC_PORT> <UDP_DST_PORT> | |
`); | |
process.exit(-1); | |
} | |
// Get ports | |
const pIn = process.argv[2] | 0; | |
const pOut = process.argv[3] | 0; | |
// Create UDP Client | |
const client = dgram.createSocket('udp4'); | |
// Create TCP Server | |
const tcpServer = net.createServer(socket => { | |
socket.on('data', (d) => { | |
client.send(d, pOut); | |
}); | |
}); | |
// Bind | |
tcpServer.listen(pIn); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment