.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.botdetection.ip_lists Namespace Reference

Functions

Tuple[bool, str] pass_ip (IPv4Address|IPv6Address real_ip, config.Config cfg)
Tuple[bool, str] block_ip (IPv4Address|IPv6Address real_ip, config.Config cfg)
Tuple[bool, str] ip_is_subnet_of_member_in_list (IPv4Address|IPv6Address real_ip, str list_name, config.Config cfg)

Variables

 logger = logger.getChild('ip_limit')
list SEARXNG_ORG

Detailed Description

.. _botdetection.ip_lists:

Method ``ip_lists``
-------------------

The ``ip_lists`` method implements :py:obj:`block-list <block_ip>` and
:py:obj:`pass-list <pass_ip>`.

.. code:: toml

   [botdetection.ip_lists]

   pass_ip = [
     '167.235.158.251', # IPv4 of check.searx.space
     '192.168.0.0/16',  # IPv4 private network
     'fe80::/10',       # IPv6 linklocal
   ]

   block_ip = [
     '93.184.216.34',   # IPv4 of example.org
     '257.1.1.1',       # invalid IP --> will be ignored, logged in ERROR class
   ]

Function Documentation

◆ block_ip()

Tuple[bool, str] searx.botdetection.ip_lists.block_ip ( IPv4Address | IPv6Address real_ip,
config.Config cfg )
Checks if the IP on the subnet is in one of the members of the
``botdetection.ip_lists.block_ip`` list.

Definition at line 62 of file ip_lists.py.

62def block_ip(real_ip: IPv4Address | IPv6Address, cfg: config.Config) -> Tuple[bool, str]:
63 """Checks if the IP on the subnet is in one of the members of the
64 ``botdetection.ip_lists.block_ip`` list.
65 """
66
67 block, msg = ip_is_subnet_of_member_in_list(real_ip, 'botdetection.ip_lists.block_ip', cfg)
68 if block:
69 msg += " To remove IP from list, please contact the maintainer of the service."
70 return block, msg
71
72

References ip_is_subnet_of_member_in_list().

Here is the call graph for this function:

◆ ip_is_subnet_of_member_in_list()

Tuple[bool, str] searx.botdetection.ip_lists.ip_is_subnet_of_member_in_list ( IPv4Address | IPv6Address real_ip,
str list_name,
config.Config cfg )

Definition at line 73 of file ip_lists.py.

75) -> Tuple[bool, str]:
76 for net in cfg.get(list_name, default=[]):
77 try:
78 net = ip_network(net, strict=False)
79 except ValueError:
80 logger.error("invalid IP %s in %s", net, list_name)
81 continue
82 if real_ip.version == net.version and real_ip in net:
83 return True, f"IP matches {net.compressed} in {list_name}."
84 return False, f"IP is not a member of an item in the f{list_name} list"

Referenced by block_ip(), and pass_ip().

Here is the caller graph for this function:

◆ pass_ip()

Tuple[bool, str] searx.botdetection.ip_lists.pass_ip ( IPv4Address | IPv6Address real_ip,
config.Config cfg )
Checks if the IP on the subnet is in one of the members of the
``botdetection.ip_lists.pass_ip`` list.

Definition at line 49 of file ip_lists.py.

49def pass_ip(real_ip: IPv4Address | IPv6Address, cfg: config.Config) -> Tuple[bool, str]:
50 """Checks if the IP on the subnet is in one of the members of the
51 ``botdetection.ip_lists.pass_ip`` list.
52 """
53
54 if cfg.get('botdetection.ip_lists.pass_searxng_org', default=True):
55 for net in SEARXNG_ORG:
56 net = ip_network(net, strict=False)
57 if real_ip.version == net.version and real_ip in net:
58 return True, f"IP matches {net.compressed} in SEARXNG_ORG list."
59 return ip_is_subnet_of_member_in_list(real_ip, 'botdetection.ip_lists.pass_ip', cfg)
60
61

References ip_is_subnet_of_member_in_list().

Here is the call graph for this function:

Variable Documentation

◆ logger

searx.botdetection.ip_lists.logger = logger.getChild('ip_limit')

Definition at line 39 of file ip_lists.py.

◆ SEARXNG_ORG

list searx.botdetection.ip_lists.SEARXNG_ORG
Initial value:
1= [
2 # https://github.com/searxng/searxng/pull/2484#issuecomment-1576639195
3 '167.235.158.251', # IPv4 check.searx.space
4 '2a01:04f8:1c1c:8fc2::/64', # IPv6 check.searx.space
5]

Definition at line 41 of file ip_lists.py.