Skip to content

Instantly share code, notes, and snippets.

@martinbutt
Created September 29, 2022 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinbutt/ae94ad44e0509dbf3cc70c519c437b02 to your computer and use it in GitHub Desktop.
Save martinbutt/ae94ad44e0509dbf3cc70c519c437b02 to your computer and use it in GitHub Desktop.
BASH IP address (IPv4 and IPv6) validator
[[ $IP =~ ^([1-9]?[0-9]\.|1[0-9]{2}\.|2[0-4][0-9]\.|25[0-5]\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$ ]] || >&2 echo "Error: IP address '${IP}' is not valid"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment