Created
July 14, 2013 08:31
-
-
Save nitinsatish/5993625 to your computer and use it in GitHub Desktop.
Find Free IP addresses from DHCP configuration file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import re | |
config_file='/etc/dhcpd.conf' | |
ips_used=[] | |
not_used=[] | |
try : | |
dhcp_config=open(config_file,'r') | |
for lin in dhcp_config : | |
match=re.search(r'^fixed-address\ \d+\.\d+\.\d+\.(\d+);',lin) | |
if match : | |
ips_used.append(match.group(1)) | |
#print ips_used | |
for i in range(1,254) : | |
if str(i) not in ips_used : | |
not_used.append(i) | |
print "IP addresses available in 192.168.1.0/24" | |
print not_used | |
except: | |
print "Not able to find DHCP config file." | |
finally: | |
dhcp_config.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment