Ip processing shell code that some might find useful

Hi all,

Not sure if this counts as a project but I wanted to share with you a script which I adopted, modified and partially re-wrote, and which contains some useful functions for ipv4 and ipv6 processing and manipulation. This is only partially my code but the original script is licensed under GPLv2, so I'm feeling free to modify and share it (the link to the original is included in the readme, in case anyone's interested).

As a whole, the script trims an ipv4 or ipv6 address to a given length (expressed in CIDR mask bits) and outputs the resulting subnet.

Some functions that are included are ipv6 expansion, ipv6 compression, bitwise ip AND mask calculation, and ip validation (utilizing 2 methods: regex and the 'ip route' command).

I decided to keep the script POSIX-compatible. Works on my OpenWRT router and probably should work on any OpenWRT system.

Here's the link:



Update: worked some more on this script. Lots of small reliability improvements, better code readability and better code comments. Ah, and also should be compatible with any Unix machine now, except the part that utilizes the 'ip route get' command for ip validation, which probably won't work on every Unix. But now the script auto-detects if it's working and if not then falls back to regex validation.