Check if network subnets are overlapping each other.
Use ipconflict Python package (source) to check if two or more network subnets are overlapping.
Install ipconflict
Pythopn package.
$ pip3 install ipconflict
Defaulting to user installation because normal site-packages is not writeable Collecting ipconflict Downloading ipconflict-0.5.0-py2.py3-none-any.whl (16 kB) Collecting py-radix Downloading py-radix-0.10.0.tar.gz (21 kB) Preparing metadata (setup.py) ... done Requirement already satisfied: netaddr in /usr/lib/python3/dist-packages (from ipconflict) (0.8.0) Collecting tqdm Downloading tqdm-4.64.1-py2.py3-none-any.whl (78 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 78.5/78.5 KB 1.3 MB/s eta 0:00:00 Building wheels for collected packages: py-radix Building wheel for py-radix (setup.py) ... done Created wheel for py-radix: filename=py_radix-0.10.0-cp310-cp310-linux_x86_64.whl size=50897 sha256=d170ed0f783ffe973e03530aabd4dd3ee1e00d3c4a260a90cfb9c8174843b6ad Stored in directory: /home/milosz/.cache/pip/wheels/6d/29/5a/e5083f47e00dd79bf1e95d93c452440cff80d7ca16215cabed Successfully built py-radix Installing collected packages: py-radix, tqdm, ipconflict WARNING: The script tqdm is installed in '/home/milosz/.local/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. WARNING: The script ipconflict is installed in '/home/milosz/.local/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Successfully installed ipconflict-0.5.0 py-radix-0.10.0 tqdm-4.64.1
Ensure that binary directory is in PATH.
$ echo $PATH
/home/milosz/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin
$ export PATH=$PATH:~/.local/bin/
Update ~/.bashrc
file accordingly.
Display help information.
$ ipconflict --help
usage: ipconflict [-h] [-f FROM_FILE] [-i] [-o] [-p] [-q] [-V] [subnets ...] Check for conflicts between subnets. positional arguments: subnets list of subnets to be checked options: -h, --help show this help message and exit -f FROM_FILE, --from-file FROM_FILE load subnet definitions from file (one per line) -i, --from-stdin load subnet definitions from stdin -o, --ip-only print only the overlapping IP addresses -p, --print-conflicts print overlapping IP addresses -q, --quiet show progress status -V, --version print ipconflict version examples: ipconflict 10.0.0.0/24 10.0.0.1/16 ipconflict 10.0.0.0/24 10.0.0.20-10.0.0.25 ipconflict -f my-subnets.txt ipconflict -f my-subnets.txt 192.168.0.0/24 exit status: 0: one or more conflicts found 1: no conflict found 2: aborted or invalid input
Check two network subnets for conflicts.
$ ipconflict 172.16.26.0/23 172.16.27.64/26
100%|███████████████████████████████████████████| 2/2 [00:00<00:00, 13530.01subnet/s] conflict found: 172.16.26.0/23 <-> 172.16.27.64/26
Inspect exit code.
$ echo $?
0
Use quiet mode.
$ ipconflict --quiet 172.16.26.0/23 172.16.27.64/26
conflict found: 172.16.26.0/23 <-> 172.16.27.64/26
Display conflicting IP addresses.
$ ipconflict --quiet --ip-only --print-conflicts 172.16.26.0/23 172.16.27.64/26
172.16.27.64 172.16.27.65 172.16.27.66 172.16.27.67 172.16.27.68 172.16.27.69 172.16.27.70 172.16.27.71 172.16.27.72 172.16.27.73 172.16.27.74 172.16.27.75 172.16.27.76 172.16.27.77 172.16.27.78 172.16.27.79 172.16.27.80 172.16.27.81 172.16.27.82 172.16.27.83 172.16.27.84 172.16.27.85 172.16.27.86 172.16.27.87 172.16.27.88 172.16.27.89 172.16.27.90 172.16.27.91 172.16.27.92 172.16.27.93 172.16.27.94 172.16.27.95 172.16.27.96 172.16.27.97 172.16.27.98 172.16.27.99 172.16.27.100 172.16.27.101 172.16.27.102 172.16.27.103 172.16.27.104 172.16.27.105 172.16.27.106 172.16.27.107 172.16.27.108 172.16.27.109 172.16.27.110 172.16.27.111 172.16.27.112 172.16.27.113 172.16.27.114 172.16.27.115 172.16.27.116 172.16.27.117 172.16.27.118 172.16.27.119 172.16.27.120 172.16.27.121 172.16.27.122 172.16.27.123 172.16.27.124 172.16.27.125 172.16.27.126 172.16.27.127
Check different networks.
$ ipconflict --quiet 172.16.27.0/26 172.16.27.64/26
no conflict found
$ echo $?
1
Additional notes
You can also display IP addresses for given network (172.16.29.48/28
), but notice that the list includes network (first) and broadcast (last) address.
$ ipconflict --quiet --ip-only --print-conflicts 172.16.29.48/28 0.0.0.0/0
172.16.29.48 172.16.29.49 172.16.29.50 172.16.29.51 172.16.29.52 172.16.29.53 172.16.29.54 172.16.29.55 172.16.29.56 172.16.29.57 172.16.29.58 172.16.29.59 172.16.29.60 172.16.29.61 172.16.29.62 172.16.29.63
Calculate usable IP addresses for given network (172.16.29.48/28
).
$ expr $(ipconflict --quiet --ip-only --print-conflicts 172.16.29.32/28 0.0.0.0/0 | wc -l) - 2
14