Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-tcp-proxy

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-tcp-proxy - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

.eslintrc.json

18

package.json

@@ -5,14 +5,20 @@ {

"license": "MIT",
"version": "0.0.5",
"version": "0.0.6",
"main": "index.js",
"repository": {
"type": "git",
"type": "git",
"url": "https://github.com/tewarid/node-tcp-proxy.git"
},
"bin" : {
"tcpproxy" : "./tcp-proxy-cli.js"
"bin": {
"tcpproxy": "./tcp-proxy-cli.js"
},
"dependencies": {
"optimist": "latest"
}
"optimist": "^0.6.1"
},
"devDependencies": {
"eslint": "^4.0.0",
"eslint-config-google": "^0.8.0",
"eslint-plugin-security": "^1.4.0"
},
"false": {}
}

@@ -1,2 +0,2 @@

# node-tcp-proxy
# node-tcp-proxy [![Codacy Badge](https://api.codacy.com/project/badge/Grade/3e3d035c4b78445bbec6fb348cf027e1)](https://www.codacy.com/app/tewarid/node-tcp-proxy?utm_source=github.com&utm_medium=referral&utm_content=tewarid/node-tcp-proxy&utm_campaign=Badge_Grade)

@@ -14,3 +14,3 @@ A simple TCP proxy that may be used to access a service on another network. An extensible replacement for socat when used thus

```bash
node tcpproxy.js --proxyPort port1 [--hostname [IP]] --serviceHost host --servicePort port2 [--q]
tcpproxy --proxyPort port1 [--hostname [IP]] --serviceHost host --servicePort port2 [--q]
```

@@ -33,3 +33,3 @@

var proxy = require("node-tcp-proxy");
var newProxy = proxy.createProxy(8080, "hostname", 10080);
var newProxy = proxy.createProxy(8080, "host", 10080);
```

@@ -43,2 +43,2 @@

`hostname` can be provided through an optional fourth parameter e.g. `{hostname: 0.0.0.0}` to `createProxy`. Console output may be silenced by using `quiet: true` e.g. `{hostname: 0.0.0.0, quiet: true}`.
`hostname` can be provided through an optional fourth parameter e.g. `{hostname: 0.0.0.0}` to `createProxy`. Console output may be silenced by adding `quiet: true` e.g. `{hostname: 0.0.0.0, quiet: true}`.
#!/usr/bin/env node
var proxy = require("./tcp-proxy.js");
var argv = require("optimist")
.usage('Usage: $0 --proxyPort [port] [--hostname [IP]] --serviceHost [host] --servicePort [port] [--q]')
.demand(['proxyPort', 'serviceHost', 'servicePort'])
.boolean('q')
.usage("Usage: $0 --proxyPort [port] [--hostname [IP]]"
+ " --serviceHost [host] --servicePort [port] [--q]")
.demand(["proxyPort", "serviceHost", "servicePort"])
.boolean("q")
.argv;

@@ -15,5 +16,6 @@

var newProxy = proxy.createProxy(argv.proxyPort, argv.serviceHost, argv.servicePort, options);
var newProxy = proxy.createProxy(argv.proxyPort, argv.serviceHost,
argv.servicePort, options);
process.on("uncaughtException", function (err) {
process.on("uncaughtException", function(err) {
console.info(err);

@@ -20,0 +22,0 @@ });

var net = require("net");
module.exports = {
createProxy: function(proxyPort, serviceHost, servicePort, options) {
return new Proxy(proxyPort, serviceHost, servicePort, options);
}
}
function uniqueKey(socket) {
var key = socket.remoteAddress + ':' + socket.remotePort;
var key = socket.remoteAddress + ":" + socket.remotePort;
return key;
}
function Proxy(proxyPort, serviceHost, servicePort, options) {
function TcpProxy(proxyPort, serviceHost, servicePort, options) {
this.proxyPort = proxyPort;

@@ -24,17 +18,17 @@ this.serviceHost = serviceHost;

Proxy.prototype.createProxy = function () {
this.log("Proxy listening at port " + this.proxyPort);
TcpProxy.prototype.createProxy = function() {
this.log("proxy listening at port " + this.proxyPort);
var proxy = this;
proxy.server = net.createServer(function (proxySocket) {
proxy.server = net.createServer(function(proxySocket) {
var key = uniqueKey(proxySocket);
proxy.log("Client connected from " + key);
proxy.log("client connected from " + key);
proxy.proxySockets[key] = proxySocket;
var connected = false;
var buffers = new Array();
var buffers = [];
var serviceSocket = new net.Socket();
serviceSocket.connect(proxy.servicePort, proxy.serviceHost, function () {
serviceSocket.connect(proxy.servicePort,
proxy.serviceHost, function() {
connected = true;

@@ -47,6 +41,6 @@ if (buffers.length > 0) {

});
serviceSocket.on("data", function (data) {
serviceSocket.on("data", function(data) {
proxySocket.write(data);
});
serviceSocket.on("close", function (had_error) {
});
serviceSocket.on("close", function(hadError) {
proxy.log("service socket closed");

@@ -56,3 +50,3 @@ proxy.log(" ending proxy socket");

});
serviceSocket.on("error", function (e) {
serviceSocket.on("error", function(e) {
proxy.log("service socket error");

@@ -64,7 +58,7 @@ proxy.log(e);

proxySocket.on("error", function (e) {
proxySocket.on("error", function(e) {
proxy.log("proxy socket error");
proxy.log(e);
});
proxySocket.on("data", function (data) {
});
proxySocket.on("data", function(data) {
if (connected) {

@@ -76,12 +70,11 @@ serviceSocket.write(data);

});
proxySocket.on("close", function (had_error) {
proxySocket.on("close", function(hadError) {
delete proxy.proxySockets[uniqueKey(proxySocket)];
serviceSocket.destroy();
});
}).listen(proxy.proxyPort, proxy.options.hostname);
}
};
Proxy.prototype.end = function () {
this.log("Terminating proxy");
TcpProxy.prototype.end = function() {
this.log("terminating proxy");
this.server.close();

@@ -92,11 +85,13 @@ for (var key in this.proxySockets) {

this.server.unref();
}
};
Proxy.prototype.log = function (msg) {
try {
if (!this.options || !this.options.quiet) {
console.log(msg);
}
} catch(e) {
TcpProxy.prototype.log = function(msg) {
if (!this.options || !this.options.quiet) {
console.log(msg);
}
}
};
module.exports.createProxy = function(proxyPort,
serviceHost, servicePort, options) {
return new TcpProxy(proxyPort, serviceHost, servicePort, options);
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc