# @sansamour/node-socks

> A simple SOCKS/HTTP/HTTPS proxy implementation

Latest version **1.1.5** (published 2022-06-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install @sansamour/node-socks
pnpm add @sansamour/node-socks
yarn add @sansamour/node-socks
bun add @sansamour/node-socks
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.5 |
| Published | 2022-06-30 |
| First published | 2020-08-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 44.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Gert Van Gool |
| Maintainers | sansamour |
| Keywords | socks |

## Links

- npm: https://www.npmjs.com/package/@sansamour/node-socks
- Repository: https://github.com/sansamour/node-socks
- Homepage: https://github.com/sansamour/node-socks#readme
- Issues: https://github.com/sansamour/node-socks/issues
- npm.io page: https://npm.io/package/@sansamour/node-socks

## Dependencies (1)

- [ssh2](https://npm.io/package/ssh2.md) ^0.8.9

## Recent versions

- 1.1.5 (latest) — 2022-06-30
- 1.1.3 — 2020-11-07
- 1.1.2 — 2020-11-05
- 1.1.1 — 2020-08-05
- 1.1.0 — 2020-08-05
- 1.0.0 — 2020-08-02

## README

SOCKS/HTTP/HTTPS proxy implementation in node.js
===============================

A simple SOCKS/HTTP/HTTPS proxy implementation and demo proxy in `node.js <http://nodejs.org>`_.
 
It supports both socks5/socks4/socks4a/http/https proxy
You can run it easily as:

>  node ./test/socksproxy5.js

>  node ./test/socksproxy4.js

>  node ./test/httpproxy.js

Under windows you can run run.vbs

This will create a proxy socks5 at ``127.0.0.1`` on port ``8888``.

This will create a proxy socks4 socks4a at ``127.0.0.1`` on port ``9999``.

This will create a proxy http https at ``127.0.0.1`` on port ``8080``.

All with _user:password_ is _user:pass_

You can use this as a good starting point for writing a proxy or a tunnel!

## Features

* Supports SOCKS v4, v4a, and v5 proxy.
* Supports HTTP/HTTPS proxy.
* Supports the CONNECT and ASSOCIATE for SOCKS v5.
* Supports user/pass authentication.
* Supports Banned IPs.
* Supports SSH relay (since v1.1.0).

## Installation

`npm install @sansamour/node-socks`

## Usage

```typescript
// TypeScript
import { http, socks4, socks5 } from '@sansamour/node-socks';

// ES6 JavaScript
import { http, socks4, socks5 } from '@sansamour/node-socks';

// Legacy JavaScript
const socks5 = require('@sansamour/node-socks').socks5;

http.createServer(options);
socks4.createServer(options);
socks5.createServer(options);
```

Options
-------

* **authorization** - (< _function_ >validateUserPassword) A function with two parameters (_user_, _password_).

* **fileBannedIPs** - File location with content banned IPs semicolon separated.

* **onAccept** - A callback function with four parameters (_socket_, _info_, _accept_, _deny_)
    * **info** < _object_ > {_srcAddr_, _srcPort_, _dstAddr_, _dstPort_, _numClients_}
	
* **ssh** - < _object_ > {_host_, _port_, _username_, _password_}

* **timeout** (< _number_ > miliseconds) default: 60000

## Quick Start Example

Create SOCKS v5 server: socks5://user:pass@127.0.0.1:9999 with file banned IPs `ip.txt` (semicolon separated)

```javascript
const { socks5 } = require('@sansamour/node-socks')

socks5.createServer({
	authorization: function(u,p){
		return u == 'user' && p == 'pass'
	},
	port: 9999,
	fileBannedIPs: './ip.txt'
});
```

With SOCKS v4/v4a proxy server support only Username Authentication (no Password).
Create SOCKS v4/v4a server: socks4://user:anypass@127.0.0.1:8888 with file banned IPs `ip.txt` (semicolon separated)

```javascript
const { socks4 } = require('@sansamour/node-socks')

socks4.createServer({
	authorization:function(u){
		return u == 'user'
	},
	port: 8888,
	fileBannedIPs: './ip.txt'
});
```

SSH relay example
```javascript
const { socks5 } = require('@sansamour/node-socks')

socks5.createServer({	
	port: 9999,
	ssh:{
	    host: '103.92.28.100',
	    port: 22,
	    username: 'root',
	    password: 'xxxx'
	}
});
```

Example with onAccept: limit number of clients 

```javascript
    onAccept:function(socket, info, accept, deny){
		console.log(info)
		if(info.numClients > 100){
			return deny()
		}
		accept();
	}
```

Associate Example (UDP Relay) with SOCKS v5

## Further Reading:

Detail about this package.
http://tutorialspots.com/nodejs-create-socks4socks4asocks5httphttps-proxy-server-with-authentication-5653.html

Please read the SOCKS 5 specifications for more information on how to use Associate.
http://www.ietf.org/rfc/rfc1928.txt

## License

This work is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).

---
_Source: https://npm.io/package/@sansamour/node-socks · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
