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

node-socksv5

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-socksv5

SOCKS protocol version 5 server and client implementations for node.js

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
236
increased by46.58%
Maintainers
1
Weekly downloads
 
Created
Source

Description

SOCKS protocol version 5 server and client implementations for node.js

Requirements

Tested on

  • node.js -- v12.20.1

Install

npm install node-socksv5

Examples

  • Server with no authentication and allowing all connections:
import {Server, Auth} from "node-socksv5";

const srv = new Server();
srv.listen(1080, 'localhost', () => {
	console.log('SOCKS server listening on port 1080');
});
srv.useAuth(Auth.none());
  • Server with username/password authentication and allowing all (authenticated) connections:
import {Server, Auth} from "node-socksv5";

const srv = new Server();
srv.listen(1080, 'localhost', () => {
	console.log('SOCKS server listening on port 1080');
});
srv.useAuth(srv.useAuth(Auth.userPass((username, password) => {
	if (username === 'nodejs' && password === 'rules!') {
		return Promise.resolve();
	} else {
		return Promise.reject();
	}
}));
  • Server with no authentication and denying all connections not made to port 80:
import {Server, Auth} from "node-socksv5";

const srv = new Server({}, (info, accept, deny) => {
  if (info.destination.port === 80) {
    accept();
  } else {
    deny();
  }
});
srv.listen(1080, 'localhost', () => {
	console.log('SOCKS server listening on port 1080');
});
srv.useAuth(Auth.none());
  • Server with no authentication, intercepting all connections to port 80, and passing through all others:
import {Server, Auth} from "node-socksv5";

const srv = new Server({}, (info, accept, deny) => {
  if (info.destination.port === 80) {
		const socket = await accept();
		var body = 'Hello ' + info.source.ip + '!\n\nToday is: ' + (new Date());
		socket.end([
			'HTTP/1.1 200 OK',
			'Connection: close',
			'Content-Type: text/plain',
			'Content-Length: ' + Buffer.byteLength(body),
			'',
			body
		].join('\r\n'));
	} else {
		accept();
	}
});
srv.listen(1080, 'localhost', () => {
	console.log('SOCKS server listening on port 1080');
});
srv.useAuth(Auth.none());
  • Client with no authentication:
import {Client, Auth} from "node-socksv5";

const client = new Client({
	proxy: {
		host: "127.0.0.1",
		port: 1080,
	},
	destination: {
		host: "google.com",
		port: 80,
	},
	auths: [ Auth.none() ],
}, (socket) => {
	console.log('>> Connection successful');
	socket.write('GET /node.js/rules HTTP/1.0\r\n\r\n');
	socket.pipe(process.stdout);
});

Keywords

FAQs

Package last updated on 23 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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