|
- #!/bin/sh
- #
- # legal IP address judgement.
- # version 0.2.0
- # 2004-12-28
- #
- if [ "$1" = '-h' -o "$1" = '' ]
- then
- echo -e "\n Usage: $0 IP_address\nExample: $0 192.168.1.1\n"
- exit 0
- fi
- illegalip(){
- echo $myip is Illegal IP address!
- exit 1
- }
- legalip(){
- if [ "$testip" -ge 0 -a "$testip" -le 255 ]
- then
- :
- else
- illegalip
- fi
- }
- myip=$1
- # if the string is not combin by "0-9" and "."; it is not a legal IP address.
- testip=$(echo $myip|sed -e 's/[0-9.]//g')
- if [ "$testip" != "" ]
- then illegalip
- fi
- # if the string is not format as x.x.x.x; it is not a legal IP address.
- testip=$(echo $myip|sed -n '/^[0-9]\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)[0-9]$/!p')
- if [ "$testip" != "" ]
- then illegalip
- fi
- # the ip x.x.x.x; if each x is not between 0-255, it is illegal IP address.
- for ((i=1;i<5;i++))
- do
- testip=$(echo $myip|sed -e "s/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\\$i/")
- legalip
- done
- echo $myip is legal IP address!
复制代码
ps: 换回gnome了
如果有什么好的建议,请多多指教 :thank |
|