Monday, April 21, 2025

IP Range - List Generator - Python

#Enter any IP from subnet, for example, 192.168.0.1

ip = input('Enter IP: ')
parts = ip.split('.')

print(parts)

a = '.'

start = int(input('Start num:'))
end = int(input('End num: '))

for x in range(start, end + 1):
    print(parts[0] + a + parts[1] + a + parts[2] + a + str(x))

  1. The code imports no external module.
  2. ip is a string that holds the value of the IP address entered by the user.
  3. parts is a list of four strings, where each string is obtained by splitting the ip string using the period character . as the delimiter.
  4. a is a string containing a period character.
  5. start and end are two integers that the user enters to specify the range of numbers to append to the IP address.
  6. The for loop iterates over the range of numbers from start to end (inclusive) and prints out the concatenation of the first three elements of parts separated by a, followed by the current number in the loop converted to a string.

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...