[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
IP range expandator
From: |
andreyev |
Subject: |
IP range expandator |
Date: |
Tue, 13 May 2003 21:21:31 -0300 |
User-agent: |
Mutt/1.3.25i |
Saudaçoes pessoal da lista!
Tem algum tempo que venho quebrando a cabeça para escrever um shell script para
'expandir' endereços IP de um range fornecido...
Atualmente ele 'repete' alguns IP's...
Segue o código que eu tenho até o momento:
=====================
#!/bin/bash
usage_fnt ()
{
echo "usage: $0 RANGE_INIT RANGE_END"
echo -e "where: \t RANGE_INIT is the first IP of the range and"
echo -e "\t RANGE_END is the last IP of the range."
exit 1
}
# testa se foram definidos dois argumentos
[ $# -ne 2 ] && usage_fnt
# armazena os terceiros e quartos segmentos em variaveis $SEG*_*
SEGMENTO3_1=$(echo $1| cut -d '.' -f 3)
SEGMENTO4_1=$(echo $1| cut -d '.' -f 4)
SEGMENTO3_2=$(echo $2| cut -d '.' -f 3)
SEGMENTO4_2=$(echo $2| cut -d '.' -f 4)
# testa a validade dos segmentos
for s in $SEGMENTO3_1 $SEGMENTO4_1 $SEGMENTO3_2 $SEGMENTO4_2
do if test $s -gt 254
then echo "$s não é um segmento valido!"
usage_fnt
fi
done
# testa se os segmentos não estam fora de ordem
if test $SEGMENTO3_1 -gt $SEGMENTO3_2
then echo "$1 é menor que $2"
usage_fnt
fi
# imprime a lista de IPs
if [ -n $(expr 254 - $SEGMENTO4_1) -a $SEGMENTO3_2 -ne $SEGMENTO3_1 ]
then for t in $(seq $SEGMENTO4_1 254)
do echo ww.xx.$SEGMENTO3_1.$t
done
fi
if [ $(expr $SEGMENTO3_1 + 1) -ne $SEGMENTO3_2 -a $SEGMENTO3_1 -ne $(expr
$SEGMENTO3_2 - 1) -a $(expr $SEGMENTO3_2 - 1) -gt 0 ]
then for g in $(seq $(expr $SEGMENTO3_1 + 1) $(expr $SEGMENTO3_2 - 1))
do for u in $(seq 1 254)
do echo ww.xx.$g.$u
done
done
fi
if [ $SEGMENTO4_2 -ge 1 ]
then for t in $(seq 1 $SEGMENTO4_2)
do echo nn.xx.$SEGMENTO3_2.$t
done
fi
=====================
Ainda é um código bem 'tosco', mas espero a contribuição da lista para deixa-lo
funcional e funcionando!
Desde já grato,
Andreyev
ps: eu uso apenas para expandir IP internos, ou seja, os dois primeiros
'conjuntos' não mudam, e isso deixa o codigo mais facil, mas menos 'flexivel'
para outros usos/lugares; por isso do nn.xx.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- IP range expandator,
andreyev <=