代理上的DNS? [英] DNS over proxy?

查看:39
本文介绍了代理上的DNS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几天里,我一直在努力寻找一个好的解决方案,以防止通过 socks4/5 代理发生 DNS 泄漏.

I've been pulling my hair out over the past few days looking around for a good solution to prevent DNS leaks over a socks4/5 proxy.

我查看了 SocksiPy(-branch) 模块,并尝试封装一些东西(urllib、urllib2、dnstools),但它们似乎仍然会泄漏 DNS 请求.pyCurl 也是如此.

I've looked into the SocksiPy(-branch) module, and tried to wrap a number of things (urllib,urllib2,dnstools), but they all seem to still leak DNS requests. So does pyCurl.

我知道proxychains/proxyresolv 可以通过socks4/5 代理抛出DNS 请求,它使用一些LD_PRELOAD 库来实现猴子补丁套接字的功能,就像SocksiPy 一样,但我似乎无法理解找出为什么它不通过socks4 或socks5 代理发送DNS.

I know that proxychains/proxyresolv can throw DNS requests over a socks4/5 proxy, and it does all it's magic with some LD_PRELOAD libraries to monkey-patch socket's functions, much like SocksiPy does, but I can't seem to figure out why it doesn't send DNS over either a socks4 or socks5 proxy.

我想对于 linux 我也许可以使用带有 libproxychains.so 的 CTypes 来解决我的问题,但我正在寻找多平台的东西,所以我认为猴子修补套接字模块是要走的路.

I suppose for linux I may be able to use CTypes with libproxychains.so to do my resolution, but I'm looking for something multi-platform, so I think monkey-patching the socket module is the way to go.

有没有人想出一个好方法来解决这个问题?为了可移植性,我想在代码中完成这一切,而且我不想诉诸于运行另一个代理服务器!

Has anyone figured out a good way to get around this? I want to do it all in-code for portability's sake, and I don't want to resort to running another proxy server!

谢谢!

推荐答案

好吧,我想通了.您需要在开始使用套接字之前设置默认代理(例如,在导入使用它的任何内容之前).您还需要对套接字的 getaddrinfo 部分进行猴子补丁,然后一切正常.

Well I figured it out. You need to set your default proxy BEFORE you start using the socket (e.g. before you import anything that uses it.). You also need to monkeypatch the getaddrinfo part of socket, then everything works fine.

import socks
import socket

# Can be socks4/5
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4,'127.0.0.1', 9050)
socket.socket = socks.socksocket

# Magic!
def getaddrinfo(*args):
    return [(socket.AF_INET, socket.SOCK_STREAM, 6, '', (args[0], args[1]))]
socket.getaddrinfo = getaddrinfo

import urllib

这有效并通过您导入的任何模块代替 urllib 代理所有 DNS 请求.希望它可以帮助那里的人!

This works and proxies all DNS requests through whatever module you import in lieu of urllib. Hope it helps someone out there!

您可以在我的 博客

这篇关于代理上的DNS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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