Home
Free IPs Script! PDF Print E-mail
Thursday, 06 December 2007

So IP management can be difficult and accidentally assigning an IP that is aleady being used is easy to do. I created a script that - for me - acts as a first step in determining what IPs are not in use. I run the script choose an ip from the list and further verify it's availability using my works internal systems.

Check out the below screen shot and download the script for your own use...

 

This script employs nmap and takes advantage of it's support for multiple ways of specifying IPs (CIDR, Range, etc). Basically the script starts by doing a ping of the IP, if and only if that IP does not respond to the ping does the script further port scan it.  By pinging before port scanning you eliminate the majority of IPs that are being utilized. Ones that don't ping are further analyzed and printed if found to not respond to any of the common ports. Note, you can change the ports to scan with the services variable. Enjoy!

 

Screen Shot:

Image

 

 ==================================Cut - Paste==================================

#!/bin/sh
# Author: Ryan Bowlby
# Reason: nmap is good at telling you what is alive, this is good at the opposite.
# Descripiion: First checks if IP/s are pingable, if they aren't it checks them to see if they have any listening ports, if not it prints them.



if [ $# -le 0 ] ; then
   echo "  Usage: ./free_ips.sh {IP_range}"
   echo "Example: ./free_ips.sh 192.168.1.1-100"
   echo "Example 2: ./free_ips.sh 192.168.1.1 10.0.0.0/24 127.0.0.1"
   exit 1
fi

# SERVICES is the list of ports to scan on the host
SERVICES=21,22,23,25,53,80,137,138,139,443,445



while [ $# -gt '0' ];
do
    for i in `nmap -sP -v $1 | grep down | awk '{print $2}'`
    do
          nmap -P0 -p $SERVICES -T Aggressive $i | grep -E "open|closed" > /dev/null 2>&1
          if [ $? -eq 1 ] ; then
             echo $i
          fi
    done
shift
done
 

 ==================================Cut - Paste==================================

 

 {mxc}