Python 100 project #1: IP address list generator

I made a simple ip address list generator.


Simple ip address list generator between two given ip address:

Usage: ipaddress_list_generator.py <ip_address_1> <ip_address_2>

Output: List of ip address


import ipaddress
import sys


def main():
    if len(sys.argv) != 3:
        print(f"Make ip address list between the provided ip address.\n\n"
              f"Usage: {sys.argv[0]} ip_address_1 ip_address_2\n"
              )
        sys.exit(1)

    try:
        ipaddr1, ipaddr2 = ipaddress.ip_address(sys.argv[1]), ipaddress.ip_address(sys.argv[2])
    except ValueError:
        print("Provided value is not a valid ip address.")
        sys.exit(1)

    while ipaddr1 <= ipaddr2:
        print(ipaddr1)
        ipaddr1 += 1


if __name__ == '__main__':
    main()

Output Example:

shogokobayashi 100p $ python3 ipaddress_list_generator.py 192.168.1.100 192.168.1.10
192.168.1.100
192.168.1.101
192.168.1.102
192.168.1.103
192.168.1.104
192.168.1.105
192.168.1.106
192.168.1.107
192.168.1.108
192.168.1.109
192.168.1.110

 

Leave a Reply

Your email address will not be published. Required fields are marked *