NodeJS通过代理编写套接字

时间:2016-03-14 01:50:25

标签: node.js sockets proxy

我正在尝试通过我拥有的代理进行TCP客户端连接:

IP:12.32.492.94

port:8081

用户名:acct

传递:admin123

不完全确定如何做到这一点。有什么想法吗?

u

1 个答案:

答案 0 :(得分:0)

需要使用socks npm模块来做我想做的事情。需要一个袜子代理。

“socks”:“1.1.8”

var Socks = require('socks');

var options = {
    proxy: {
        ipaddress: "202.101.228.108", // Random public proxy 
        port: 1080,
        type: 5 // type is REQUIRED. Valid types: [4, 5]  (note 4 also works for 4a) 
    },
    target: {
        host: "google.com", // can be an ip address or domain (4a and 5 only) 
        port: 80
    },
    command: 'connect'  // This defaults to connect, so it's optional if you're not using BIND or Associate. 
};

Socks.createConnection(options, function(err, socket, info) {
    if (err)
        console.log(err);
    else {
        // Connection has been established, we can start sending data now: 
        socket.write("GET / HTTP/1.1\nHost: google.com\n\n");
        socket.on('data', function(data) {
            console.log(data.length);
            console.log(data);
        });

        // PLEASE NOTE: sockets need to be resumed before any data will come in or out as they are paused right before this callback is fired. 
        socket.resume();

        // 569 
        // <Buffer 48 54 54 50 2f 31 2e 31 20 33 30 31 20 4d 6f 76 65 64 20 50 65... 
    }
});