[英]How to solve unexpected Tor behaviour? User-agent and HTTPS protocol show my actual ip
我试图通过使用 Tor 网络来隐藏我的 IP 地址。
我在 Windows 上使用 Tor 专家包。
我已经运行了 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)
我有两个问题:
- 为什么ipecho.net
和httpbin.org
在第二次测试中的结果不同?
- 为什么我在标题中提供用户代理时会显示我自己的 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
,也无论我使用默认用户代理还是特定用户代理。
从源安装“torrequest”。 此错误已解决,但可能未发布。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.