Skip to content

Instantly share code, notes, and snippets.

@vik-y
Last active January 17, 2019 15:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vik-y/36487eaf25d5a497fe979edf46b10ab5 to your computer and use it in GitHub Desktop.
Save vik-y/36487eaf25d5a497fe979edf46b10ab5 to your computer and use it in GitHub Desktop.
Script to get all unused ips in a subnet
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
@vik-y
Copy link
Author

vik-y commented Aug 28, 2016

A subnet ip must be provided as command line argument.

@vik-y
Copy link
Author

vik-y commented Sep 1, 2016

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