【问题标题】:NodeJS writing a socket through a proxyNodeJS 通过代理编写套接字
【发布时间】:2016-03-14 01:50:25
【问题描述】:

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

IP:12.32.492.94

端口:8081

用户名:账户

通过:admin123

不完全确定该怎么做。有什么想法吗?

var client = new net.Socket();
client.connect(port, ip, function() {

});

client.on('connect', function() {
  console.log('connected');
});

client.on('data', function(data) {
  console.log(data);
});

【问题讨论】:

    标签: node.js sockets proxy


    【解决方案1】:

    需要使用 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... 
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-23
      • 2014-03-21
      • 2015-03-14
      • 2021-06-24
      • 1970-01-01
      • 2013-11-23
      相关资源
      最近更新 更多