Python Script : Display addressable IP addresses

Below is a short script designed to output the addressable IP addresses within a given subnet.

Note : This script requires the netaddr python library.

#!/usr/bin/python
import sys
from netaddr import IPNetwork

IPADDRESS = raw_input('Enter Subnet:')
try:
    for ip in IPNetwork(IPADDRESS).iter_hosts():
    print '%s' % ip
except:
print "Usage: ",sys.argv[0],"[SUBNET ID]/[NETMASK]"
    print "Output addressable ip addresses within a given subnet."

 

 

 

Rick Donato

Want to become a programming expert?

Here is our hand-picked selection of the best courses you can find online:
Python Zero to Hero course
Python Pro Bootcamp
Bash Scripting and Shell Programming course
Automate with Shell Scripting course
The Complete Web Development Bootcamp course
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial