简体   繁体   English

从Node.js中的不同IP发送HTTP请求

[英]Send HTTP request from different IPs in Node.js

Is there a way to send an HTTP request with a different IP from what I have in Node.js? 有没有办法使用与Node.js中的IP不同的IP发送HTTP请求?

I want to send a request from an IP that I choose before, and not from the IP of the server or from my computer's IP. 我想从之前选择的IP发送请求,而不是从服务器的IP或我的计算机的IP发送请求。

I know that Tor Project does this kind of manipulation, but I didn't find any library that Tor uses to do this stuff. 我知道Tor Project会进行这种操作,但是我找不到Tor用来做这些东西的库。

Is there any API or Node.js module that Tor uses to handle this kind of private browsing in Node.js? 是否有任何API或Node.js模块用于处理Node.js中的这种私人浏览?

In the node http module there is a localAddress option for binding to specific network interface. 在节点http模块中,有一个localAddress选项用于绑定到特定的网络接口。

var http = require('http');

var options = {
  hostname: 'www.example.com',
  localAddress: '202.1.1.1'
};

var req = http.request(options, function(res) {
  res.on('data', function (chunk) {
    console.log(chunk.toString());
  });
});

Check out Mikeal's Request on Github. 在Github上查看Mikeal的请求

Tor uses SOCKS5 and these two modules can help: socks5-http-client and socks5-https-client Tor使用SOCKS5,这两个模块可以帮助: socks5-http-clientsocks5-https-client

require('socks5-http-client').request(options, function(res) {
  console.log('STATUS: ' + res.statusCode);
  console.log('HEADERS: ' + JSON.stringify(res.headers));
  res.setEncoding('utf8');
  res.on('data', function (chunk) {
    console.log('BODY: ' + chunk);
  });
});

Another option is to use a free web proxy, such as the Hide My Ass web proxy . 另一种选择是使用免费的Web代理,例如Hide My Ass Web代理 They also provide a list of ip:port proxies which you can use. 它们还提供了可以使用的ip:port代理列表。 Both http, https and even SOCKS4/5. http,https甚至是SOCKS4 / 5。 Either use the above modules or simply configure your web browser to use one of them. 使用上述模块或只是将Web浏览器配置为使用其中一个。

You could even setup your own private http proxy node app and deploy on Heroku. 您甚至可以设置自己的私有http代理节点应用程序并在Heroku上部署。 I found a ton of easy to follow examples on Google. 我在Google上发现了大量易于理解的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM