shell判断ip合法性

  sre

正则:

function check_ip(){
    echo 1 | perl -ne 'exit 1 unless /\b(?:(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5]))\b/'
    if [? -eq 0 ];then
        return 0
    else
        return 1 
    fi
}

LEAVE A COMMENT

Captcha Code