Showing posts with label inline. Show all posts
Showing posts with label inline. Show all posts

May 15, 2015

How to get the unused or free IPs on linux machine?

 Inline format of the script:
lsof -nl >/tmp/lsof.log;rm -rf ~/freeIPs.log; for ip in `ip add list|grep -v "127.0.0\|::1\|0.0.0.0\|00:00:"|cut -d" " -f6|cut -d"/" -f1|grep -v qdisc|awk 'NF'`;do grep $ip /tmp/lsof.log > /dev/null; if [ $? != 0 ]; then echo $ip >> ~/freeIPs.log; fi; done; rm -rf /tmp/lsof.log;echo "Total IPs:`ip add list|grep -v "127.0.0\|::1\|0.0.0.0\|00:00:"|cut -d" " -f6|cut -d"/" -f1|grep -v qdisc|awk 'NF'|wc -l`"; echo "Free IPs:`wc -l ~/freeIPs.log`";

Script:

 lsof -nl >/tmp/lsof.log
 rm -rf ~/freeIPs.log
 for ip in `ip add list|grep -v "127.0.0\|::1\|0.0.0.0\|00:00:"|cut -d" " -f6|cut -d"/" -f1|grep -v qdisc|awk 'NF'`
 do 
     grep $ip /tmp/lsof.log > /dev/null
     if [ $? != 0 ]
    then 
          echo $ip >> ~/freeIPs.log
    fi
 done
 rm -rf  /tmp/lsof.log
 echo "Total IPs:`ip add list|grep -v "127.0.0\|::1\|0.0.0.0\|00:00:"|cut -d" " -f6|cut -d"/" -f1|grep -v qdisc|awk 'NF'|wc -l`";
 echo "Free IPs:`wc   -l ~/freeIPs.log`";