Quite simply I'd like to verify that a string represents a valid IP address in a bash script. I think like many others I've fallen into the pitfall of trying to do this with a regular expression; while this works well enough for IPv4, IPv6 is more complex (as it supports compression of zeroes) and it's just a complicated and not especially readable solution.
However, unix and linux clearly understand IP addresses well enough, so I'm wondering if there is a better way that I can validate IP addresses in bash? Preferably a reasonably common tool that can be used to do-so.
I'd like to avoid using other languages such as Python to do this, as I am in fact hoping to replace a current solution which is to use PHP's
filter_var function. It works, but as with regular expressions, it's introducing a second language where I hope to avoid using one.
Lastly, if there's a solution that can also handle IP address ranges (such as 0.0.0.0-255.255.255.255 or 0.0.0.0/16 etc.) that'd be ideal, but I can handle these myself