46def post_search(request, search):
47
48 if search.search_query.pageno > 1:
49 return True
50
51 if search.search_query.query.lower() == "tor-check":
52
53
54 try:
55 resp = get("https://check.torproject.org/exit-addresses")
56 node_list = re.findall(reg, resp.text)
57
58 except HTTPError:
59
60 search.result_container.answers["tor"] = {
61 "answer": gettext(
62 "Could not download the list of Tor exit-nodes from: https://check.torproject.org/exit-addresses"
63 )
64 }
65 return True
66
67 x_forwarded_for = request.headers.getlist("X-Forwarded-For")
68
69 if x_forwarded_for:
70 ip_address = x_forwarded_for[0]
71 else:
72 ip_address = request.remote_addr
73
74 if ip_address in node_list:
75 search.result_container.answers["tor"] = {
76 "answer": gettext(
77 "You are using Tor and it looks like you have this external IP address: {ip_address}".format(
78 ip_address=ip_address
79 )
80 )
81 }
82 else:
83 search.result_container.answers["tor"] = {
84 "answer": gettext(
85 "You are not using Tor and you have this external IP address: {ip_address}".format(
86 ip_address=ip_address
87 )
88 )
89 }
90
91 return True