Question

I have a quite huge dhcpd.conf file on my CentOS gateway with ip addresses from a few networks. With grep I find out all strings, which contains ip's from needed network. How can I find all free ip's (my network is 192.168.77.0/24).

Was it helpful?

Solution

Not bullet-proof but should work:

grep -oE '192\.168\.77\.[0-9]+' dhcpd.conf

Not bullet-proof as it will find also 192.168.77.999 which is not an IP.


Update:

If you are just searching for those which are free (you told that in comments) then use:

for ip in 192.168.77.{254..1} ; do
    grep -oE "$ip" dhcpd.conf > /dev/null 2>&1
    if [ $? != 0 ] ; then
        echo "$ip is free"
    fi
done
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top