如何使用socks4a从node.js连接到隐藏服务
How to connect to hidden service from node.js using socks4a?
TOR文档说SOCKS4a需要连接到一个隐藏的服务。有一个实现SOCKS4a的节点库。
假设一个人知道一个隐藏服务的.onion
地址,一个人应该如何用https连接到这个隐藏服务,从一个node.js
应用程序获取一个在线网页?欢迎提供一个代码示例。
更准确地说,我已经为Openshift安装了Tor墨盒,但连接和使用它对我来说是不清楚的。我在Tor栈交换上创建了一个相关的问题
通常TOR隐藏服务不使用HTTPS,因为TOR已经为通过网络路由的数据包提供了强大的加密。但有些服务确实使用它。我最近需要与TOR隐藏服务背后的web API进行通信。我是这样做的
安装TOR。在debian/Ubuntu系统上:
sudo apt-get install tor
对于其他系统,请查看官方网站的相应安装指南。
使用下面的nodejs脚本从TOR隐藏服务中获取网页。默认情况下,它将获取DuckDuckGo的home age,这是由他们的v3洋葱地址提供的。
const url = require('url');
const http = require('http');
const https = require('https');
const SocksProxyAgent = require('socks-proxy-agent');
// Use the SOCKS_PROXY env var if using a custom bind address or port for your TOR proxy:
const proxy = process.env.SOCKS_PROXY || 'socks5h://127.0.0.1:9050';
console.log('Using proxy server %j', proxy);
// The default HTTP endpoint here is DuckDuckGo's v3 onion address:
const endpoint = process.argv[2] || 'https://duckduckgogg42xjoc72x3sjasowoarfbgcmvfimaftt6twagswzczad.onion';
console.log('Attempting to GET %j', endpoint);
// Prepare options for the http/s module by parsing the endpoint URL:
let options = url.parse(endpoint);
const agent = new SocksProxyAgent(proxy);
// Here we pass the socks proxy agent to the http/s module:
options.agent = agent;
// Depending on the endpoint's protocol, we use http or https module:
const httpOrHttps = options.protocol === 'https:' ? https : http;
// Make an HTTP GET request:
httpOrHttps.get(options, res => {
// Print headers on response:
console.log('Response received', res.headers);
// Pipe response body to output stream:
res.pipe(process.stdout);
});
- 将上述脚本保存到文件
tor-http-fetch.js
- 安装
socks-proxy-agent
npm模块:npm install socks-proxy-agent
node tor-http-fetch.js
获取自己的洋葱服务:node ./tor-http-fetch.js "http://your-tor-hidden-service.onion"
上面的脚本可以使用http或https url。
详情请点击此处
祝你好运!
相关文章:
- 在单击任何位置时隐藏元素,而不检查每次DOM单击
- 显示5秒后隐藏潜水
- 在不使用JQuery的情况下隐藏DOM中的选定元素
- 剑道UI内联编辑:如何在点击其他按钮时隐藏按钮
- 浮动页脚栏-使用Bootstrap隐藏
- 在jquery中为显示/隐藏设置cookie
- 单击按钮后如何逐个调用分区,上一个分区将隐藏
- 从var向代码隐藏函数传递值
- Image赢得't隐藏在滚动jQuery上
- 是否可以将一个函数输入连接到另一个函数调用的文本
- 具有rowGrouping的数据表无法隐藏列
- Jquery隐藏未触发
- 将值连接到隐藏变量
- 在连接期间隐藏用户,不使用 goinstant
- 如果没有互联网连接,请隐藏iframe
- 使用JQuery将输入增加1,限制为9,并连接到隐藏输入
- jQuery克隆元素,然后用连接的结果填充隐藏字段,以避免空列表问题
- 隐藏内容在本地html文档,如果浏览器没有连接到互联网
- 一个帮助数据隐藏在模块化下的JavaScript连接程序
- 如何使用socks4a从node.js连接到隐藏服务