.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 IP :py:obj:`block- <block_ip>` and
:py:obj:`pass-lists <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 61 of file ip_lists.py.

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

References searx.botdetection.ip_lists.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 72 of file ip_lists.py.

74) -> Tuple[bool, str]:
75
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 searx.botdetection.ip_lists.block_ip(), and searx.botdetection.ip_lists.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 48 of file ip_lists.py.

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

References searx.botdetection.ip_lists.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 38 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 40 of file ip_lists.py.