Last active
August 29, 2015 14:05
-
-
Save felmoltor/617feed1e12e5c53aa5d to your computer and use it in GitHub Desktop.
unificarangos.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ ! -f $1 || $# -ne 2 ]];then | |
echo "Usage: $0 <file> <resultfile>" | |
else | |
resultfile=$2 | |
echo -n "" > $resultfile | |
for line in `cat $1`; do | |
line=$(echo $line | tr -d ' ') | |
if [[ $(echo $line | grep "-"| wc -l) > 0 ]];then | |
echo "Linea $line is a range" | |
deagglist=$(ipcalc $line | grep -v "deaggregate") | |
for deag in $deagglist;do | |
echo "Separando rango $deag en IP" | |
for ip in $(nmap -sL -n $deag | grep "scan report" | cut -f5 -d' ');do | |
echo $ip >> $resultfile | |
done | |
done | |
elif [[ $(echo $line | grep "/" | wc -l) > 0 ]];then | |
echo "Linea $line is a CIDR" | |
for ip in $(nmap -sL -n $line | grep "scan report" | cut -f5 -d' ');do | |
echo $ip >> $resultfile | |
done | |
else | |
echo "Linea $line is an IP" | |
echo $line >> $resultfile | |
fi | |
done | |
fi | |
sort -u $resultfile > $resultfile".uniq" | |
nips=$(wc -l $resultfile".uniq" | awk '{print $1}') | |
echo | |
echo "Range file produced $nips unique IPs" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment