[Bash] Listado IP’s

Este código no es de mucha utilidad per se, solo es una prueba de concepto de como podríamos sacar todas las IP’s de un rango dado:

#!/bin/bash
#comprobamos que han introducido al menos un parametro
if [ -z $1 ] 
	then
	  	
	echo "No ha especificado ningun parametro. Por favor incluya la IP origen del rango y la IP final del rango"
	
else
	if [ -z $2 ]
	then
		echo "Debe introducir como segundo parámetro la IP final del rango"
	else
		
		let BIT1=`echo $1 | cut -d "." -f 1`
		let BIT2=`echo $1 | cut -d "." -f 2`
		let BIT3=`echo $1 | cut -d "." -f 3`
		let BIT4=`echo $1 | cut -d "." -f 4`

		let BIT11=`echo $2 | cut -d "." -f 1`
		let BIT12=`echo $2 | cut -d "." -f 2`
		let BIT13=`echo $2 | cut -d "." -f 3`
		let BIT14=`echo $2 | cut -d "." -f 4`

		while [ "$BIT4" -lt "$BIT14" ]; do
			echo "nmap $BIT1.$BIT2.$BIT3.$BIT4"
			let "BIT4 = $BIT4 + 1"
		done


		while [ "$BIT3" -lt "$BIT13" ]; do
		        echo "nmap $BIT1.$BIT2.$BIT3.$BIT4"
	      
			let BIT4=`echo $1 | cut -d "." -f 4`
			while [ "$BIT4" -lt "$BIT14" ]; do
		        	echo "nmap $BIT1.$BIT2.$BIT3.$BIT4"
		      		let "BIT4 = $BIT4 + 1"
			done
			let "BIT3 = $BIT3 + 1"
		done


		while [ "$BIT2" -lt "$BIT12" ]; do
		        echo "nmap $BIT1.$BIT2.$BIT3.$BIT4"
		        let "BIT2 = $BIT2 + 1"
			let BIT3=`echo $1 | cut -d "." -f 3`
			while [ "$BIT3" -lt "$BIT13" ]; do
        			echo "nmap $BIT1.$BIT2.$BIT3.$BIT4"
       				let "BIT3 = $BIT3 + 1"
				let BIT4=`echo $1 | cut -d "." -f 4`         	
				while [ "$BIT4" -lt "$BIT14" ]; do
                			echo "nmap $BIT1.$BIT2.$BIT3.$BIT4"
                			let "BIT4 = $BIT4 + 1"
        			done
 			done
 		done

		while [ "$BIT1" -lt "$BIT11" ]; do
        		echo "nmap $BIT1.$BIT2.$BIT3.$BIT4"
        		let "BIT1 = $BIT1 + 1"
			let BIT2=`echo $1 | cut -d "." -f 2`	
			while [ "$BIT2" -lt "$BIT12" ]; do
        			echo "nmap $BIT1.$BIT2.$BIT3.$BIT4"
        			let "BIT2 = $BIT2 + 1"
				let BIT3=`echo $1 | cut -d "." -f 3`
	        		while [ "$BIT3" -lt "$BIT13" ]; do
        	       			echo "nmap $BIT1.$BIT2.$BIT3.$BIT4"
                			let "BIT3 = $BIT3 + 1"
					let BIT4=`echo $1 | cut -d "." -f 4`           	
					while [ "$BIT4" -lt "$BIT14" ]; do
                        			echo "nmap $BIT1.$BIT2.$BIT3.$BIT4"
                        			let "BIT4 = $BIT4 + 1"
					done
		        	done
			done
		done
	fi
fi

3 comments for “[Bash] Listado IP’s

  1. 22/08/2012 at 0:48

    Raghu comentó:

    I am totally wowed and preaperd to take the next step now.

    Desde jbahillo.com: a las 1:09 del 11/08/2012

  2. 20/08/2012 at 11:17

    Raghu comentó:

    I am totally wowed and preaperd to take the next step now.

    Desde jbahillo.com: a las 1:09 del 11/08/2012

  3. 11/08/2012 at 1:09

    I am totally wowed and preaperd to take the next step now.

Deja un comentario