现在的位置: 首页 > 综合 > 正文

Bash check IP and port

2013年03月24日 ⁄ 综合 ⁄ 共 544字 ⁄ 字号 评论关闭
33 #check arguments
34 
35 #check ip
36 pattern_ip="^(([0-9]|[1-9][0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2([0-4][0-9]|5[0-5]))$"
37 #pattern_ip="^((1?[0-9]?[0-9]|2([0-4][0-9]|5[0-5]))\.){3}(1?[0-9]?[0-9]|2([0-4][0-9]|5[0-5]))$"
38 
39 if [[ !(($1 =$pattern_ip&& ($3 =$pattern_ip)) ]] ; then
40     echo "from_ip or to_ip has errors!"
41     exit 0
42 fi
43 
44 #check port
45 pattern_port="^([0-9]{1,4}|[1-5][0-9]{4}|6[0-5]{2}[0-3][0-5])$"
46 if [[ !($2 =$pattern_port]]; then
47     echo "port has erros!"
48     exit 0;
49 fi


抱歉!评论已关闭.