从Node.js中的不同IP发送HTTP请求 [英] Send HTTP request from different IPs in Node.js

查看:369
本文介绍了从Node.js中的不同IP发送HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用与Node.js中的IP不同的IP发送HTTP请求?

Is there a way to send an HTTP request with a different IP from what I have in Node.js?

我想从IP发送请求我选择之前,而不是来自服务器的IP或我的计算机的IP。

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.

我知道Tor Project会进行这种操作,但我没有找到Tor用来做这些东西的任何库。

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是否有任何API或Node.js模块用于处理Node.js中的这种私人浏览?

Is there any API or Node.js module that Tor uses to handle this kind of private browsing in Node.js?

推荐答案

在节点http模块中有一个 localAddress 绑定到特定网络接口的选项。

In the node http module there is a localAddress option for binding to specific network interface.

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());
  });
});

查看 Mikeal的请求

Tor使用SOCKS5,这两个模块可以提供帮助: socks5-http-client socks5-https-client

Tor uses SOCKS5 and these two modules can help: socks5-http-client and socks5-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);
  });
});

另一种选择是使用免费的网络代理,例如Hide My Ass 网络代理。他们还提供了您可以使用的 ip:port proxies 列表。 http,https甚至是SOCKS4 / 5。使用上述模块或者只是将Web浏览器配置为使用其中一个模块。

Another option is to use a free web proxy, such as the Hide My Ass web proxy. They also provide a list of ip:port proxies which you can use. Both http, https and even SOCKS4/5. Either use the above modules or simply configure your web browser to use one of them.

您甚至可以设置自己的私有http代理节点应用程序并在Heroku上部署。我在谷歌上发现了很多易于理解的例子。

You could even setup your own private http proxy node app and deploy on Heroku. I found a ton of easy to follow examples on Google.

这篇关于从Node.js中的不同IP发送HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆