Skip to content

Instantly share code, notes, and snippets.

@mdzzohrabi
Created October 26, 2016 00:38
Show Gist options
  • Save mdzzohrabi/83173e52d0158c72e6a1595ff85671c1 to your computer and use it in GitHub Desktop.
Save mdzzohrabi/83173e52d0158c72e6a1595ff85671c1 to your computer and use it in GitHub Desktop.
Node.JS Simple Port Opening ( For NAT Testing )
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