The following python script calculates the network addresses in CIDR notation (ready to be set in the config to AllowedIPs =
) to route all traffic (0.0.0.0/0
) except for one address (30.31.32.33/32
) through the wireguard interface. This is usefull if you run wireguard over another tunnel (e.g. udp2raw).
$ python3
import ipaddress
n1 = ipaddress.ip_network('0.0.0.0/0')
n2 = ipaddress.ip_network('30.31.32.33/32')
l = list(n1.address_exclude(n2))