我试图获取Tor使用的外部IP,如上所述here。当使用像myip.dnsomatic.com这样的东西时,这非常慢。我尝试了前面提到的链接(python + stem通过控制端口来控制)所提出的建议,但你得到的只是电路的IP而不能确定哪一个是exitnode上的那个,有时是真正的IP甚至不在结果中。
任何帮助都将不胜感激。
此外,从底部的here开始,Amine提出了一种在Tor中更新身份的方法。有一条指令, controller.get_newnym_wait(),他用它来等待新连接准备就绪(控制器来自steam.control中的Control),是不是有类似的东西在Steam(对不起,我检查过,双重/三重检查,无法找到任何内容)告诉你Tor正在改变它的身份?
答案 0 :(得分:2)
您可以在不调用geoip站点的情况下获取出口节点ip。
然而,这是在不同的stackexchange站点 - https://tor.stackexchange.com/questions/3253/how-do-i-trap-circuit-id-none-errors-in-the-stem-script-exit-used-py
由@mirimir发布他的代码下面基本上附加了一个流事件监听器函数,然后用它来获取电路ID,电路指纹,然后最后是退出ip地址 -
#!/usr/bin/python
import functools
import time
from stem import StreamStatus
from stem.control import EventType, Controller
def main():
print "Tracking requests for tor exits. Press 'enter' to end."
print
with Controller.from_port() as controller:
controller.authenticate()
stream_listener = functools.partial(stream_event, controller)
controller.add_event_listener(stream_listener, EventType.STREAM)
raw_input() # wait for user to press enter
def stream_event(controller, event):
if event.status == StreamStatus.SUCCEEDED and event.circ_id:
circ = controller.get_circuit(event.circ_id)
exit_fingerprint = circ.path[-1][0]
exit_relay = controller.get_network_status(exit_fingerprint)
t = time.localtime()
print "datetime|%d-%02d-%02d %02d:%02d:%02d % (t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec)
print "website|%s" % (event.target)
print "exitip|%s" % (exit_relay.address)
print "exitport|%i" % (exit_relay.or_port)
print "fingerprint|%s" % exit_relay.fingerprint
print "nickname|%s" % exit_relay.nickname
print "locale|%s" % controller.get_info("ip-to-country/%s" % exit_relay.address, 'unknown')
print
答案 1 :(得分:0)
您可以使用此代码检查当前IP(将SOCKS_PORT值更改为您的):
import re
import stem.process
import requesocks
SOCKS_PORT = 9053
tor_process = stem.process.launch_tor()
proxy_address = 'socks5://127.0.0.1:{}'.format(SOCKS_PORT)
proxies = {
'http': proxy_address,
'https': proxy_address
}
response = requesocks.get("http://httpbin.org/ip", proxies=proxies)
print re.findall(r'[\d.-]+', response.text)[0]
tor_process.kill()
答案 2 :(得分:0)
如果你想使用袜子,你应该这样做:
pip install requests[socks]
然后你可以这样做:
import requests
import json
import stem.process
import stem
SOCKS_PORT = "9999"
tor = stem.process.launch_tor_with_config(
config={
'SocksPort': SOCKS_PORT,
},
tor_cmd= 'absolute_path/to/tor.exe',
)
r = requests.Session()
proxies = {
'http': 'socks5://localhost:' + SOCKS_PORT,
'https': 'socks5://localhost:' + SOCKS_PORT
}
response = r.get("http://httpbin.org/ip", proxies=proxies)
self.current_ip = response.json()['origin']