Last active
January 17, 2019 15:52
-
-
Save vik-y/36487eaf25d5a497fe979edf46b10ab5 to your computer and use it in GitHub Desktop.
Script to get all unused ips in a subnet
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
import os, sys | |
# Fping must be installed in the system | |
os.system('fping -a -g %s/24 > alive.txt' % (sys.argv[1])) | |
f = open('alive.txt', 'r') | |
raw = f.readlines() | |
ips = [int(x.split('.')[-1].strip()) for x in raw] | |
ips.sort() | |
# From the sorted list figure out the unused ips. | |
print ips |
Instructions to run :
sudo apt-get install fping
NOTE: Final list printed gives the list of used IPs. So pick an IP which is not in the list.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A subnet ip must be provided as command line argument.