Skip to main content

Posts

Showing posts from June, 2014

Shell Script with Python module to find total ip address between two ip Addresses

################################################### # Script Name : noOfHosts # Created By : Jino Joseph # Created Date : 08-Jul-2014 # Last Modified : 08-Jul-2014 # Purpose : To find the Total number of Hosts between two ip addresses. ################################################### #!/bin/bash sed -i 's/\t/#/g' ips.txt for i in `cat /root/ips.txt`; do IPFROM=$(echo $i | awk -F '#' '{print $1}'); IPTO=$(echo $i | awk -F '#' '{print $2}'); python -c " import ipaddress import sys ip1 = int(ipaddress.IPv4Address(unicode('"$IPFROM"'))) ip2 = int(ipaddress.IPv4Address(unicode('"$IPTO"'))) host = ip2 - ip1 Nhost = host + 1 sys.stdout.write(str(Nhost)) " echo " $IPFROM $IPTO"; done ################################################### This will give the result as "Number of IP" , "FromIP" , "ToIP". Each lines of ips.txt file