Re: validate IP address via bash - anyone have one!
On 10 Aug 2003 20:27:37 -0700, hallian wrote:[color=blue]
> Hello -
>
> Anybody using a script to validate IP address in bash! Just finding a
> quick fix rather than getting into those regular expression! It would
> be helpful, if someone could shoot me out a link![/color]
[url]http://www.tldp.org/LDP/abs/html/index.html[/url]
snippet from my ckip script to test multi ip address for a FQDN.
_isp=comcast.net
_domain=${_isp}
tput clear
echo
_fn=/tmp/mail
host mail.${_domain} > $_fn
chmod 666 $_fn
_mail_name="mail.${_domain}"
_item_count=0
_item_total=4
while read line
do
set -- $line
if [ $1 != $_mail_name ] ; then
echo "1: mail $1 <> $_mail_name modify /etc/postfix/main.cf sender_cano
nical"
fi
shift $(($#-1))
case $1 in
63.240.76.10) _item_count=$(($_item_count+1)) ;;
204.127.202.10) _item_count=$(($_item_count+1)) ;;
204.127.198.10) _item_count=$(($_item_count+1)) ;;
216.148.227.80) _item_count=$(($_item_count+1)) ;;
*) echo "2: Mail: invalid last word $1"
echo $line
echo Modify firewall
;;
esac
done < $_fn
if [ $_item_count != $_item_total ] ; then
echo 3: Item count $_item_count ne $_item_total
cat $_fn
fi
if [ $_deb -eq 0 ] ; then
/bin/rm $_fn
fi