.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.plugins.tor_check Namespace Reference

Functions

 post_search (request, search)
 

Variables

bool default_on = False
 
 name = gettext("Tor check plugin")
 
 description
 
str preference_section = 'query'
 
list query_keywords = ['tor-check']
 
str query_examples = ''
 
 reg = re.compile(r"(?<=ExitAddress )\S+")
 

Detailed Description

A plugin to check if the ip address of the request is a Tor exit-node if the
user searches for ``tor-check``.  It fetches the tor exit node list from
https://check.torproject.org/exit-addresses and parses all the IPs into a list,
then checks if the user's IP address is in it.

Enable in ``settings.yml``:

.. code:: yaml

  enabled_plugins:
    ..
    - 'Tor check plugin'

Function Documentation

◆ post_search()

searx.plugins.tor_check.post_search ( request,
search )

Definition at line 46 of file tor_check.py.

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 # Request the list of tor exit nodes.
54 try:
55 resp = get("https://check.torproject.org/exit-addresses")
56 node_list = re.findall(reg, resp.text)
57
58 except HTTPError:
59 # No answer, return error
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

References searx.format.

Variable Documentation

◆ default_on

bool searx.plugins.tor_check.default_on = False

Definition at line 22 of file tor_check.py.

◆ description

searx.plugins.tor_check.description
Initial value:
1= gettext(
2 "This plugin checks if the address of the request is a Tor exit-node, and"
3 " informs the user if it is; like check.torproject.org, but from SearXNG."
4)

Definition at line 27 of file tor_check.py.

◆ name

searx.plugins.tor_check.name = gettext("Tor check plugin")

Definition at line 24 of file tor_check.py.

◆ preference_section

str searx.plugins.tor_check.preference_section = 'query'

Definition at line 33 of file tor_check.py.

◆ query_examples

str searx.plugins.tor_check.query_examples = ''

Definition at line 39 of file tor_check.py.

◆ query_keywords

list searx.plugins.tor_check.query_keywords = ['tor-check']

Definition at line 36 of file tor_check.py.

◆ reg

searx.plugins.tor_check.reg = re.compile(r"(?<=ExitAddress )\S+")

Definition at line 43 of file tor_check.py.