I have the following bash script to validate IP addresses:
#!/bin/bash
validFormatIP()
{
grep -E -q '^(25[0-4]|2[0-4][0-9]|1[0-9][0-9]|[1]?[1-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)' <<< "$1" && echo "Valid IP" || echo "Invalid IP"
}
validFormatIP $1
It validates IP addresses properly for the first, second and third bytes but not the fourth byte.
Here's the output of my script to better illustrate what is going wrong:
$ ./script.bash 1000.33.0.1
Invalid IP
$ ./script.bash 34.1000.0.1
Invalid IP
$ ./script.bash 34.33.1000.1
Invalid IP
$ ./script.bash 34.33.0.1000
Valid IP
$
As you can see it accepts 1000
as a valid value for the last byte even though it's actually invalid.
Any one have any idea where the problem is?