si vous avez un netmask du style: fffcac00
voici comment le convertir avec sed/awk:

$ echo fffcac00 |sed 's/\(..\)/\1 /g' |awk '{printf ("%d.%d.%d.%d\n","0x"$1,"0x"$2,"0x"$3,"0x"$4)}'
255.252.172.0

- on sépare tout les deux caracteres par un espace.
- on utilise awk pour travailler sur chaque champ séparé par un espace.
- on utilise le printf de awk pour convertir l’hexa en décimal.

 

ce script n’est pas de moi mais c’est un bon aide mémoire sur les bitwise

#!/bin/ksh

typeset -i2 mask=255

[[ $# != 2 ]] && {
   echo "Usage: $0 ipaddress subnetmask"
   exit 1
}

SaveIFS=$IFS
IFS=.
set -A IParr $1
set -A NMarr $2
IFS=$SaveIFS

typeset -i2 ipbin1=${IParr[0]}
typeset -i2 ipbin2=${IParr[1]}
typeset -i2 ipbin3=${IParr[2]}
typeset -i2 ipbin4=${IParr[3]}

typeset -i2 nmbin1=${NMarr[0]}
typeset -i2 nmbin2=${NMarr[1]}
typeset -i2 nmbin3=${NMarr[2]}
typeset -i2 nmbin4=${NMarr[3]}

echo
echo "       IP Address: $1"
echo "      Subnet Mask: $2"
echo "  Network Address: $((ipbin1 & nmbin1)).$((ipbin2 & nmbin2)).$((ipbin3 & nmbin3)).$((ipbin4 & nmbin4))"
echo "Broadcast Address: $((ipbin1 | (mask ^ nmbin1))).$((ipbin2 | (mask ^ nmbin2))).$((ipbin3 | (mask ^ nmbin3))).$((ipbin4 | (mask ^ nmbin4)))"
echo
© 2011 Unix Open Suffusion theme by Sayontan Sinha