Skip to content

Instantly share code, notes, and snippets.

View KevinRohn's full-sized avatar
🏃‍♂️

Kevin Rohn KevinRohn

🏃‍♂️
View GitHub Profile
@KevinRohn
KevinRohn / validate_ipv4.sh
Created November 3, 2023 15:06
validate IPv4
#!/bin/bash
IP=$1
result=`echo $IP | awk -F"\." ' $0 ~ /^([0-9]{1,3}\.){3}[0-9]{1,3}$/ && $1 <=255 && $2 <= 255 && $3 <= 255 && $4 <= 255 '` 2>/dev/null
if [ "$result" = "" ]; then
echo "IPv4 is invalid: $IP"
exit 1
fi
exit 0