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
59 commits
Select commit Hold shift + click to select a range
43a6aaa
use socks5.js in cluse
sunnyboy00 Nov 3, 2012
ac764f9
use socks5.js instead of socks
sunnyboy00 Nov 3, 2012
95d9fbd
Ensure that more than two process
sunnyboy00 Nov 4, 2012
6cb545c
sunnyboy00 Nov 4, 2012
5f80c6c
add “ uncaughtException ” catch
sunnyboy00 Nov 4, 2012
85acb0b
change server.listen(PORT, HOST) to server.listen(PORT);
sunnyboy00 Nov 4, 2012
d01fd17
run in windows
sunnyboy00 Nov 5, 2012
95bc9aa
add domain
sunnyboy00 Nov 6, 2012
3a5c8a8
bug fix
sunnyboy00 Nov 6, 2012
d2b77b9
bug fix
sunnyboy00 Nov 6, 2012
06de52a
bug fix
sunnyboy00 Nov 7, 2012
d808965
Update README.rst
sunnyboy00 Nov 18, 2012
351e7d2
Update AUTHORS
sunnyboy00 Nov 18, 2012
d8e5c7d
bug fix of domain
sunnyboy00 Nov 24, 2012
14af4af
Update socks.js
sunnyboy00 Dec 15, 2012
dea278a
Update README.rst
sunnyboy00 Dec 15, 2012
b08ef13
Update README.rst
sunnyboy00 Dec 15, 2012
64f4079
Update socks.js
sunnyboy00 Dec 15, 2012
991e23f
Update socks.js
sunnyboy00 Dec 15, 2012
79377a6
sunnyboy00 Dec 16, 2012
b9dd286
sunnyboy00 Dec 16, 2012
bca289b
rename socks.js socks5.js
sunnyboy00 Dec 16, 2012
50a88b0
sunnyboy00 Dec 16, 2012
1159c6d
sunnyboy00 Dec 16, 2012
d9b780f
sunnyboy00 Dec 16, 2012
22a5501
sunnyboy00 Dec 16, 2012
523b8eb
Update README.rst
sunnyboy00 Dec 16, 2012
eec9985
bug fix
sunnyboy00 Dec 16, 2012
da78c10
sunnyboy00 Dec 16, 2012
95b67a5
Update README.rst
sunnyboy00 Dec 16, 2012
e51ffd9
add socks5 udp support
sunnyboy00 Dec 16, 2012
90e7f0b
cluster bug fix
sunnyboy00 Dec 16, 2012
487abf1
cluster bug fix
sunnyboy00 Dec 16, 2012
6e28ada
use for proxy chains
sunnyboy00 Dec 21, 2012
eb8b456
add socks4a support
sunnyboy00 Dec 23, 2012
941d685
Update README.rst
sunnyboy00 Dec 23, 2012
9aa0c5a
socks4a bug fix
sunnyboy00 Dec 23, 2012
305a2fb
iplist used for ip authentication
sunnyboy00 Jan 2, 2013
25cc235
add ip authentication
sunnyboy00 Jan 2, 2013
a7ebb4e
add ip authentication
sunnyboy00 Jan 2, 2013
28f9ec0
add 'ip.txt' file watch
sunnyboy00 Jan 11, 2013
f59fcfb
add 'ip.txt' file watch
sunnyboy00 Jan 11, 2013
b0605b7
sunnyboy00 Jan 14, 2013
a940afe
add timeout
sunnyboy00 Jan 14, 2013
b29c2fe
timeout bug fix
sunnyboy00 Jan 20, 2013
189e13a
timeout bug fix
sunnyboy00 Jan 20, 2013
d3a5ea8
timeout bug fix
sunnyboy00 Jan 20, 2013
bdd3473
add http https proxy support
sunnyboy00 Mar 30, 2013
fac4c36
bug fix
sunnyboy00 Mar 31, 2013
2350302
Update run.vbs
sunnyboy00 Mar 31, 2013
b240d31
Update README.rst
sunnyboy00 Mar 31, 2013
1d7c7b8
Update http.js
sunnyboy00 Jun 22, 2013
69c39dc
Update socks4.js
sunnyboy00 Jun 22, 2013
39e1361
Update socksproxy5.js
sunnyboy00 Jun 22, 2013
8a35082
use blacklist for ip.txt
sunnyboy00 Aug 24, 2013
01842c3
use for blacklist
sunnyboy00 Aug 24, 2013
99c26fa
use blacklist for ip.txt
sunnyboy00 Aug 24, 2013
4cd8e2a
use blacklist for ip.txt
sunnyboy00 Aug 24, 2013
9b72017
bug fix for udp
sunnyboy00 Aug 24, 2013
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>
sunnyboy00 <gc063tzf@163.com>
13 changes: 9 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ SOCKS implementation in node.js
===============================

A simple SOCKS implementation and demo proxy in `node.js <http://nodejs.org>`_.


It supports both socks5 and socks4.
You can run it easily as::

./socks

This will create a proxy at ``127.0.0.1`` on port ``8888``.
./socksproxy5.js
./socksproxy4.js
./http.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``.

You can use this as a good starting point for writing a proxy or a tunnel!
38 changes: 38 additions & 0 deletions chains.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var net = require('net');
var proxyhost="127.0.0.1";//����������IP
var proxyport=9999;//�������Ķ˿�
var listenport=8124;//�����˿�
net.createServer(function (socket) {
socket.on("connect",function(){
console.log('connected');
try{
var db=net.createConnection(proxyport,proxyhost);
db.on("connect",function(){
console.log("server connected");
socket.on("data", function (data) {
db.write(data);
});
db.on("data",function(data){
//console.log(data.toString('utf8',0,data.legnth));
//console.log(data);
socket.write(data);
});
socket.on("close",function(){
console.log("server closed");
db.end();
});
});
db.on("error",function(data){
console.log("error:\r\n"+data);
db.end();
socket.end();
});
db.on("end",function(){
console.log("server closed");
socket.end();
});
}catch(err){
console.log(err);
}
});
}).listen(listenport, "0.0.0.0");
197 changes: 197 additions & 0 deletions http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
var net=require('net');
var local_port=8080;

//�ڱ��ش���һ��server��������local_port�˿�
var sockserver=net.createServer(function (client)
{

//���ȼ��������������ݷ����¼���ֱ���յ������ݰ���������http����ͷ
var buffer=new Buffer(0);
client.on('data',function (data)
{
buffer=buffer_add(buffer,data);
if(buffer_find_body(buffer)==-1)return ;
var req=parse_request(buffer);
if(req===false)return ;
client.removeAllListeners('data');
relay_connection(req);
});

//��http����ͷ��ȡ��������Ϣ�󣬼��������������������ݣ�ͬʱ����Ŀ��������������Ŀ�������������ݴ���������
function relay_connection(req)
{
console.log(req.method+' '+req.host+':'+req.port);

//������������CONNECT������GET, POST������ô�滻��ͷ����һЩ����
if(req.method!='CONNECT')
{
//�ȴ�buffer��ȡ��ͷ��
var _body_pos=buffer_find_body(buffer);
if(_body_pos<0)_body_pos=buffer.length;
var header=buffer.slice(0,_body_pos).toString('utf8');
//�滻connectionͷ
header=header.replace(/(proxy\-)connection\:.+\r\n/ig,'')
.replace(/Keep\-Alive\:.+\r\n/i,'')
.replace("\r\n",'\r\nConnection: close\r\n');
//�滻��ַ��ʽ(ȥ����������)
if(req.httpVersion=='1.1')
{
var url=req.path.replace(/http\:\/\/[^\/]+/,'');
if(url.path!=url)header=header.replace(req.path,url);
}
buffer=buffer_add(new Buffer(header,'utf8'),buffer.slice(_body_pos));
}

//������Ŀ��������������
var server=net.createConnection(req.port,req.host);
//������������������������
client.on("data",function (data){
try
{server.write(data);}
catch (e)
{ }
});
server.on("data",function (data){
try
{client.write(data);}
catch (e)
{ }
});
server.on("end",function (e){
console.log("server close");
console.log(e);
try
{client.end();}
catch (e)
{ }
});
server.on("error",function (e){
console.log("server close");
console.log(e);
try
{client.destroy();}
catch (e)
{ }
});

client.on("end",function (e){
try
{server.end();}
catch (e)
{ }
});
client.on("error",function (e){
try
{server.destroy();}
catch (e)
{ }
});
if(req.method=='CONNECT')
client.write(new Buffer("HTTP/1.1 200 Connection established\r\nConnection: close\r\n\r\n"));
else
server.write(buffer);
}
});

//�������ִ���
process.on('uncaughtException',function (err)
{
console.log("\nError!!!!");
console.log(err);
});

sockserver.on('listening', function() {
var address = sockserver.address();
console.log('LISTENING %s:%s', address.address, address.port);
});


/**
* ������ͷ��ȡ��������ϸ��Ϣ
* ������ CONNECT ��������ô�᷵�� { method,host,port,httpVersion}
* ������ GET/POST ���������� { metod,host,port,path,httpVersion}
*/
function parse_request(buffer)
{
var s=buffer.toString('utf8');
var method=s.split('\n')[0].match(/^([A-Z]+)\s/)[1];
if(method=='CONNECT')
{
var arr=s.match(/^([A-Z]+)\s([^\:\s]+)\:(\d+)\sHTTP\/(\d\.\d)/);
if(arr&&arr[1]&&arr[2]&&arr[3]&&arr[4])
return {method:arr[1],host:arr[2],port:arr[3],httpVersion:arr[4]};
}
else
{
var arr=s.match(/^([A-Z]+)\s([^\s]+)\sHTTP\/(\d\.\d)/);
if(arr&&arr[1]&&arr[2]&&arr[3])
{
var host=s.match(/Host\:\s+([^\n\s\r]+)/)[1];
if(host)
{
var _p=host.split(':',2);
return {method:arr[1],host:_p[0],port:_p[1] ? _p[1]:80,path:arr[2],httpVersion:arr[3]};
}
}
}
return false;
}




/**
* ����buffer����������
*/
function buffer_add(buf1,buf2)
{
var re=new Buffer(buf1.length+buf2.length);
buf1.copy(re);
buf2.copy(re,buf1.length);
return re;
}

/**
* �ӻ������ҵ�ͷ����������("\r\n\r\n")��λ��
*/
function buffer_find_body(b)
{
for(var i=0,len=b.length-3;i<len;i++)
{
if(b[i]==0x0d&&b[i+1]==0x0a&&b[i+2]==0x0d&&b[i+3]==0x0a)
{
return i+4;
}
}
return -1;
}
//////////////////////////////////////////////////////////////////////////
var exec = require('child_process').exec;
var cluster = require('cluster');

var numCPUs = require('os').cpus().length;


if (cluster.isMaster) {

for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
if(1==numCPUs) cluster.fork();//make sure it is more than 2

cluster.on('exit', function(worker, code, signal) {
if (worker.suicide !== true) {
exec('taskkill /pid '+worker.process.pid +' /T /F');
}
var exitCode = worker.process.exitCode;
console.log('worker ' + worker.process.pid + ' died ('+exitCode+'). restarting...');

cluster.fork();

});
} else {
sockserver.listen(8080);

}


1 change: 1 addition & 0 deletions ip.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
;
3 changes: 3 additions & 0 deletions run.vbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
createobject("wscript.shell").run "cmd /c node socksproxy5",0
createobject("wscript.shell").run "cmd /c node socksproxy4",0
createobject("wscript.shell").run "cmd /c node http",0
60 changes: 0 additions & 60 deletions socks

This file was deleted.

Loading