shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [shell-script] Mascara + Rede


From: Fábio Gomes
Subject: Re: [shell-script] Mascara + Rede
Date: Mon, 10 Dec 2007 17:00:32 -0200
User-agent: Thunderbird 2.0.0.9 (X11/20071031)

Flavio Junior wrote:

Pega os 4 campos do IP e faz:

$ echo "obase=2;$CAMPO" | bc -l

sem mto tempo..

--

Flavio do Carmo Junior

On Dec 10, 2007 2:09 PM, Fábio Gomes <address@hidden <mailto:fabio%40uniconet.com.br>> wrote:
>
>
>
>
>
>
> Boa tarde lista,
>
> Alguem sabe alguma função que me retorne a rede em binario, eu
> informando ip e a mascara?
>
> Eu estou usando...
>
> IP_IF2=$(/sbin/ifconfig ${IF_LINK2} | awk '/inet addr:/ {print $2}' |
> cut -d: -f2)
> MASK_IF2=$(/sbin/ifconfig ${IF_LINK2} | awk '/inet addr:/ {print $4}' |
> cut -d: -f2)
> REDE2=$(ipmask $MASK_IF2 $IP_IF2 | cut -f2 -d" ")
>
> Mas preciso que seja em binario, preciso saber se eh /24, /18, etc...
>
> Obrigado
>
> Fábio Gomes dos Santos
>



Segue o resultado ae...

Quem quiser incrementar fique avontade :D

#!/bin/bash
if_link=$1
if [ "${if_link}" == "" ]; then
       echo "Use $0 ethX
exemplo: $0 eth0"
       exit 1
fi
ip_if=$(/sbin/ifconfig ${if_link} | awk '/inet addr:/ {print $2}' | cut -d: -f2) mask_if=$(/sbin/ifconfig ${if_link} | awk '/inet addr:/ {print $4}' | cut -d: -f2)
rede=$(ipmask $mask_if $ip_if | cut -f2 -d" ")
IFS="."
mask_bin=0
for i in $mask_if
do
case $i in
       0)
       mask_bin=`expr $(($mask_bin+0))`
       ;;
       128)
       mask_bin=`expr $(($mask_bin+1))`
       ;;
       192)
       mask_bin=`expr $(($mask_bin+2))`
       ;;
       224)
       mask_bin=`expr $(($mask_bin+3))`
       ;;
       240)
       mask_bin=`expr $(($mask_bin+4))`
       ;;
       248)
       mask_bin=`expr $(($mask_bin+5))`
       ;;
       252)
       mask_bin=`expr $(($mask_bin+6))`
       ;;
       254)
       mask_bin=`expr $(($mask_bin+7))`
       ;;
       255)
       mask_bin=`expr $(($mask_bin+8))`
       ;;
esac
done
IFS=" "
echo ${rede}/${mask_bin}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]