Consider adding a better increment ip function . last_ip maxes out at 254 in current implementation
Here is an implementation of function nextip() for your consideration to supports netmask lower than 24. It needs a bit more work and assumes last-ip.txt is not empty
Diff file attacheda.diff
Edited by Anand Setlur