Skip to content
This repository was archived by the owner on Jan 24, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e0aebaf
export socks.js for require
Oct 21, 2013
d1f6155
fixed extract server port
Oct 21, 2013
b42e8b4
rename it as socks5
Oct 22, 2013
2293ecd
support socks4,socks4a
Oct 24, 2013
ae185f7
code cleanup
Oct 24, 2013
9a1902b
code cleanup
Nov 9, 2013
d144bbe
fixed sock write
Nov 22, 2013
a6cfc65
fixed sock write
Nov 22, 2013
b5ec23d
fixed error check
Nov 22, 2013
e84edb5
fixed error check
Nov 22, 2013
2362d73
check Address.read exception
Dec 2, 2013
2b77203
ignore exception
Dec 2, 2013
263184d
disable info log
Jul 6, 2014
cac1c57
fix author list
Jul 6, 2014
a7bece2
fix wrong Port when using DNS
Mar 13, 2015
ffbe0c7
we can binding NIC now.
Mar 13, 2015
2308131
Merge pull request #1 from jjm2473/master
sequoiar Jun 7, 2015
d43e38d
fixed port read when use dns
sequoiar Jun 7, 2015
259cb12
Update README.rst
sequoiar Jul 10, 2016
1215cfe
Create README.md
sequoiar Jul 10, 2016
9ec7361
Update README.md
sequoiar Jul 10, 2016
0ec7dd4
Delete README.rst
sequoiar Jul 10, 2016
c7f1939
Update README.md
sequoiar Jul 10, 2016
1f51c16
fixed README.md add install step
sequoiar Jul 10, 2016
90b29c8
Update package.json
sequoiar Jul 10, 2016
e1d2c47
Update package.json
sequoiar Jul 10, 2016
aa9ea71
Update package.json
sequoiar Jul 10, 2016
3c4c9aa
Update README.md
sequoiar Sep 7, 2016
932c42a
release v1.0.0
sequoiar Sep 14, 2016
842463d
added go.js
Dec 23, 2016
b67dd6e
fixed socks5 typo
Jan 11, 2017
3d1488e
support username/password auth
Jan 12, 2017
d312c2d
remove go.js
Jan 12, 2017
3566b12
support user/pass auth
Jan 12, 2017
601f8bf
fixed typo
Jan 12, 2017
fc3c509
use user/pass force auth
sequoiar Jan 12, 2017
29b6de0
fixed typo
sequoiar Jan 12, 2017
fb95e48
fixed typo
Jan 12, 2017
4b49dfb
fixed typo
sequoiar Jan 12, 2017
ab8ef45
fixed socks support username/password auth
Jan 12, 2017
06f8626
Merge branch 'master' of https://github.com/sequoiar/socks5
Jan 12, 2017
fe4d27a
tag 1.0.1
Jan 12, 2017
62b0179
Update proxy.js
sequoiar Jan 13, 2017
c02cddc
Update README.md
sequoiar Jan 25, 2017
3c76be8
Update README.md
sequoiar Jan 25, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Gert Van Gool <gertvangool@gmail.com>
John Cant <a.johncant@gmail.com>
Tom Zhou <iwebpp@gmail.com>
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SOCKS v4/v4a/v5 server implementation with user/pass authentication node.js
=============================================================================

A simple SOCKS v5/v4/v4a server implementation and demo proxy.

You can run it easily as::

node proxy.js

This will create a proxy at ``127.0.0.1`` on port ``8888``.

You can use this as a good starting point for writing a proxy or a tunnel!

### Install
- npm install socks5


### License

(The MIT License)
12 changes: 0 additions & 12 deletions README.rst

This file was deleted.

24 changes: 20 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
{
"name": "node-socks"
, "version": "0.1.0"
, "description": "A simple SOCKS implementation and demo proxy"
, "author": "Gert Van Gool <gertvangool@gmail.com>"
"name": "socks5"
, "version": "1.0.1"
, "description": "A simple SOCKS 5/4/4a implementation and demo proxy"
, "author": [
"Gert Van Gool <gertvangool@gmail.com>",
"Tom Zhou <iwebpp@gmail.com>"
]
, "repository": {
"type": "git",
"url": "git://github.com/sequoiar/socks5.git"
}
, "keywords": [
"socks",
"socks5",
"socks4",
"socks4a",
"proxy",
"http"
]
, "main": "socks.js"
, "dependencies": {
}
}
100 changes: 100 additions & 0 deletions proxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@

var net = require('net'),
socks = require('./socks.js'),
info = console.log.bind(console);

// Create server
// The server accepts SOCKS connections. This particular server acts as a proxy.
var HOST='127.0.0.1',
PORT='8888',
server = socks.createServer(function(socket, port, address, proxy_ready) {

// Implement your own proxy here! Do encryption, tunnelling, whatever! Go flippin' mental!
// I plan to tunnel everything including SSH over an HTTP tunnel. For now, though, here is the plain proxy:

var proxy = net.createConnection({port:port, host:address,localAddress:process.argv[2]||undefined}, proxy_ready);
var localAddress,localPort;
proxy.on('connect', function(){
info('%s:%d <== %s:%d ==> %s:%d',socket.remoteAddress,socket.remotePort,
proxy.localAddress,proxy.localPort,proxy.remoteAddress,proxy.remotePort);
localAddress=proxy.localAddress;
localPort=proxy.localPort;
}.bind(this));
proxy.on('data', function(d) {
try {
//console.log('receiving ' + d.length + ' bytes from proxy');
if (!socket.write(d)) {
proxy.pause();

socket.on('drain', function(){
proxy.resume();
});
setTimeout(function(){
proxy.resume();
}, 100);
}
} catch(err) {
}
});
socket.on('data', function(d) {
// If the application tries to send data before the proxy is ready, then that is it's own problem.
try {
//console.log('sending ' + d.length + ' bytes to proxy');
if (!proxy.write(d)) {
socket.pause();

proxy.on('drain', function(){
socket.resume();
});
setTimeout(function(){
socket.resume();
}, 100);
}
} catch(err) {
}
});

proxy.on('error', function(err){
//console.log('Ignore proxy error');
});
proxy.on('close', function(had_error) {
try {
if(localAddress && localPort)
console.log('The proxy %s:%d closed', localAddress, localPort);
else
console.error('Connect to %s:%d failed', address, port);
socket.end();
} catch (err) {
}
}.bind(this));

socket.on('error', function(err){
//console.log('Ignore socket error');
});
socket.on('close', function(had_error) {
try {
if (this.proxy !== undefined) {
proxy.removeAllListeners('data');
proxy.end();
}
//console.error('The socket %s:%d closed',socket.remoteAddress,socket.remotePort);
} catch (err) {
}
}.bind(this));

}, process.argv[3]&&process.argv[4]&&{username:process.argv[3],password:process.argv[4]});

server.on('error', function (e) {
console.error('SERVER ERROR: %j', e);
if (e.code == 'EADDRINUSE') {
console.log('Address in use, retrying in 10 seconds...');
setTimeout(function () {
console.log('Reconnecting to %s:%s', HOST, PORT);
server.close();
server.listen(PORT, HOST);
}, 10000);
}
});
server.listen(PORT, HOST);

// vim: set filetype=javascript syntax=javascript :
60 changes: 0 additions & 60 deletions socks

This file was deleted.

Loading