Created
October 26, 2016 00:38
-
-
Save mdzzohrabi/83173e52d0158c72e6a1595ff85671c1 to your computer and use it in GitHub Desktop.
Node.JS Simple Port Opening ( For NAT Testing )
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 process = require( 'process' ); | |
const [ nodePath , scriptPath , port ] = process.argv; | |
if ( port === undefined ) { | |
console.error( 'Port not defined' ); | |
return; | |
} | |
const server = net.createServer(( client ) => { | |
console.log( `New Connection from ${client.remoteAddress}:${client.remotePort}` ); | |
client.end('Hi !! ( Masoud Zohrabi <[email protected]> )'); | |
}); | |
server.listen( { host: '0.0.0.0' , port: port } , () => { | |
var { address , port } = server.address(); | |
console.log( `Server started on ${address}:${port}` ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment