The COUNTRIES dictionary maps ISO country codes to country names.
from pynicotine.networkfilter import NetworkFiltercountry_name = NetworkFilter.COUNTRIES.get("US")print(country_name) # Output: United States# List all countriesfor code, name in NetworkFilter.COUNTRIES.items(): print(f"{code}: {name}")
IP banning and ignoring supports wildcard patterns:
192.168.1.* - Matches all IPs in 192.168.1.0/24 subnet
10.*.*.* - Matches all IPs in 10.0.0.0/8 subnet
172.16.*.5 - Matches specific IPs across subnets
from pynicotine.core import core# Ban entire subnetcore.network_filter.ban_user_ip(ip_address="192.168.1.*")# Check if specific IP is bannedis_banned = core.network_filter.is_user_ip_banned( ip_address="192.168.1.100")print(is_banned) # Output: True
Filtered users are persisted in the configuration:
from pynicotine.config import config# Access ban listsbanlist = config.sections["server"]["banlist"]ignorelist = config.sections["server"]["ignorelist"]ipblocklist = config.sections["server"]["ipblocklist"]ipignorelist = config.sections["server"]["ipignorelist"]
Changes to ban and ignore lists are automatically persisted to the configuration file.
from pynicotine.core import core# Ban a spammercore.network_filter.ban_user("spammer")# Ignore an annoying usercore.network_filter.ignore_user("annoying")# Ban IP rangecore.network_filter.ban_user_ip(ip_address="10.0.0.*")# Check user statusif core.network_filter.is_user_banned("spammer"): print("User is banned")if core.network_filter.is_user_ip_banned(ip_address="10.0.0.5"): print("IP is banned")# Later, unban if neededcore.network_filter.unban_user("spammer")core.network_filter.unban_user_ip(ip_address="10.0.0.*")