我试图通过Tor网络隐藏我的ip地址。
我在windows上使用Tor expert捆绑包。
我已经运行了2个测试来比较不同的输出。
我使用了两个网站来检测ip和用户代理:ipecho.net
和httpbin.org
第一个测试结果:使用HTTP协议和默认用户代理进行呼叫:
Ipecho found this ip: 199.249.230.64 (an expected Tor ip)
Httpbin found this ip: 199.249.230.64 (an expected Tor ip)
Ipecho found this user-agent: python-requests/2.22.0 (an expected default user-agent from requests)
Httpbin found this user-agent: python-requests/2.22.0 (an expected default user-agent from requests)
但基于第二个测试结果:使用HTTP协议和特定的用户代理进行呼叫
Ipecho found this ip: <MY ACTUAL IP> (my own unexpected ip)
Httpbin found this ip: 199.249.230.64 (an expected Tor ip)
Ipecho found this user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 (an expected user-agent that we specified)
Httpbin found this user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 (an expected user-agent that we specified)
我有两个问题:
-Why ipecho.net
和httpbin.org
在第二个测试中有不同的结果?
当我在报头中提供用户代理时,-Why是否会显示我自己的ip?
以下是重现这些测试结果的完整代码:
注意:我已经将torrc文件配置为ControlPort 9051
并更改了HashedControlPassword
。
from torrequest import TorRequest # to make requests in Tor
import bs4 # to parse the responses
import json # to parse the responses
# we set up our requests for Tor with TorRequest
with TorRequest(proxy_port = 9050, ctrl_port = 9051, password = '<your password>') as tr:
# we set up a specific user-agent that we will use on some tests
headers = {'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148'}
# First test: we call with HTTP protocol and no specific user-agent
response_ipecho_ip = tr.get('http://ipecho.net/plain')
response_httpbin_ip = tr.get('http://httpbin.org/ip')
response_ipecho_agent = tr.get('http://ipecho.net/extra')
response_httpbin_agent = tr.get('http://httpbin.org/user-agent')
print('################ First test: we call with HTTP protocol and no specific user-agent ##############')
print('Ipecho found this ip: {}'.format(response_ipecho_ip.text))
response_httpbin_ip = json.loads(response_httpbin_ip.text)
print('Httpbin found this ip: {}'.format(response_httpbin_ip['origin']))
soup = bs4.BeautifulSoup(response_ipecho_agent.text,'html.parser')
print('Ipecho found this user-agent: {}'.format(soup.find('tr').td.findNext('td').text))
response_httpbin_agent = json.loads(response_httpbin_agent.text)
print('Httpbin found this user-agent: {}\n'.format(response_httpbin_agent['user-agent']))
# Second test: we call with HTTP protocol and a specific user agent
response_ipecho_ip = tr.get('http://ipecho.net/plain', headers = headers)
response_httpbin_ip = tr.get('http://httpbin.org/ip', headers = headers)
response_ipecho_agent = tr.get('http://ipecho.net/extra', headers = headers)
response_httpbin_agent = tr.get('http://httpbin.org/user-agent', headers = headers)
print('################ Second test: we call HTTP protocol and a specific user agent ##############')
print('Ipecho found this ip: {}'.format(response_ipecho_ip.text))
response_httpbin_ip = json.loads(response_httpbin_ip.text)
print('Httpbin found this ip: {}'.format(response_httpbin_ip['origin']))
soup = bs4.BeautifulSoup(response_ipecho_agent.text,'html.parser')
print('Ipecho found this user-agent: {}'.format(soup.find('tr').td.findNext('td').text))
response_httpbin_agent = json.loads(response_httpbin_agent.text)
print('Httpbin found this user-agent: {}\n'.format(response_httpbin_agent['user-agent']))
此外,额外的测试:我运行相同的测试,但这次使用HTTPS。我自己的ip总是显示出来,不管是ipecho.net
还是httpbin.org
,也不管我是使用默认的用户代理还是特定的用户代理。
发布于 2020-02-15 12:26:56
从源码安装torrequest。这个bug是has been solved的,但可能不会发布。
https://stackoverflow.com/questions/60238367
复制相似问题