AllowIPs Calculator for Wireguard

by James McDonald | Jun 10, 2026 | IT Tips | 0 comments

Enables one to exclude IP ranges from going across the Wireguard tunnel as needed.

https://www.procustodibus.com/blog/2021/03/wireguard-allowedips-calculator

Do it with python

>>> import ipaddress
>>> n1 = ipaddress.ip_network('0.0.0.0/0')
>>> n2 = ipaddress.ip_network('10.19.80.0/24')
>>> list(n1.ipaddress.address_exclude(n2))
[IPv4Network('128.0.0.0/1'), IPv4Network('64.0.0.0/2'), IPv4Network('32.0.0.0/3'), IPv4Network('16.0.0.0/4'), IPv4Network('0.0.0.0/5'), IPv4Network('12.0.0.0/6'), IPv4Network('8.0.0.0/7'), IPv4Network('11.0.0.0/8'), IPv4Network('10.128.0.0/9'), IPv4Network('10.64.0.0/10'), IPv4Network('10.32.0.0/11'), IPv4Network('10.0.0.0/12'), IPv4Network('10.24.0.0/13'), IPv4Network('10.20.0.0/14'), IPv4Network('10.16.0.0/15'), IPv4Network('10.18.0.0/16'), IPv4Network('10.19.128.0/17'), IPv4Network('10.19.0.0/18'), IPv4Network('10.19.96.0/19'), IPv4Network('10.19.64.0/20'), IPv4Network('10.19.88.0/21'), IPv4Network('10.19.84.0/22'), IPv4Network('10.19.82.0/23'), IPv4Network('10.19.81.0/24')]

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.