IP address validation function

Hi does anybody have a ksh/sh/bash function that i can embed into my script that i could use to validate an inputted IP address, I tried using one big long regular expression but it got very long and complicated

ie

#!/bin/ksh
echo " Please enter your IP address"
read IP
 ---some function to determine if it is valid or not

any help would be greatly appreciated

echo 190.04.50.00 | awk -F"\." ' $0 ~ /^([0-9]{1,3}\.){3}[0-9]{1,3}$/ && $1 <=255 && $2 <= 255 && $3 <= 255 && $4 <= 255 '

Sorry, is this supposed to return something when run, because it doesnt?

check this post

thanks, but could you explain how I can integrate that into my script

The following returns nothing when I enter a valid IP address

#!/bin/ksh
echo input IP address
read IP
result=`echo $IP | awk -F"\." ' $0 ~ /^([0-9]{1,3}\.){3}[0-9]{1,3}$/ && $1 <=255 && $2 <= 255 && $3 <= 255 && $4 <= 255 '`
echo $result

~

bash# ./test.script
input IP address
10.10.10.10      < this is my input
                      < see nothing returned
bash#

Remove colored code

#!/bin/ksh
echo input IP address
read IP
result=`echo $IP | awk -F"\." ' $0 ~ /^([0-9]{1,3}\.){3}[0-9]{1,3}$/ && $1 <=255 && $2 <= 255 && $3 <= 255 && $4 <= 255 '`
echo $result

Assuming a dotted quad format:

valid_dotted_quad()
{
    ERROR=0
    oldIFS=$IFS
    IFS=.
    set -f
    set -- $1
    if [ $# -eq 4 ]
    then
      for seg
      do
        case $seg in
            ""|*[!0-9]*) ERROR=1;break ;; ## Segment empty or non-numeric char
            *) [ $seg -gt 255 ] && ERROR=2 ;;
        esac
      done
    else
      ERROR=3 ## Not 4 segments
    fi
    IFS=$oldIFS
    set +f
    return ERROR
}

Test $IP with:

if valid_dotted_quad "$IP"
then
   ## IP OK
else
   ## Not OK
  printf "%s is not a valid dotted quad IP address" "$IP" >&2
fi

Note, however, that other formats can be valid IP addresses.