1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vlabodo [156]
4 years ago
15

Write a python program to read four numbers (representing the four octets of an IP) and print the next five IP addresses. Be sur

e to verify that the second, third and fourth numbers are between 0 and 255. The first one should be between 1 and 255.
Computers and Technology
1 answer:
sdas [7]4 years ago
8 0

Answer:

first_octet = int(input("Enter the first octet: "))

second_octet = int(input("Enter the second octet: "))

third_octet = int(input("Enter the third octet: "))

forth_octet = int(input("Enter the forth octet: "))

octet_start = forth_octet + 1

octet_end = forth_octet + 6

if (1 <= first_octet <= 255) and (0 <= second_octet <= 255) and (0 <= third_octet <= 255) and (0 <= forth_octet <= 255):

   for ip in range(octet_start, octet_end):

       forth_octet = forth_octet + 1

       if forth_octet > 255:

           forth_octet = (forth_octet % 255) - 1

           third_octet = third_octet + 1

           if third_octet > 255:

               third_octet = (third_octet % 255) - 1

               second_octet = second_octet + 1

               if second_octet > 255:

                   second_octet = (second_octet % 255) - 1

                   first_octet = first_octet + 1

                   if first_octet > 255:

                       print("No more available IP!")

                       break

       print(str(first_octet) + "." + str(second_octet) + "." + str(third_octet) + "." + str(forth_octet))

else:

   print("Invalid input!")

Explanation:

- Ask the user for the octets

- Initialize the start and end points of the loop, since we will be printing next 5 IP range is set accordingly

- Check if the octets meet the restrictions

- Inside the loop, increase the forth octet by 1 on each iteration

- Check if octets reach the limit - 255, if they are greater than 255, calculate the mod and subtract 1. Then increase the previous octet by 1.

For example, if the input is: 1. 1. 20. 255, next ones will be:

1. 1. 21. 0

1. 1. 21. 1

1. 1. 21. 2

1. 1. 21. 3

1. 1. 21. 4

There is an exception for the first octet, if it reaches 255 and others also reach 255, this means there are no IP available.

- Print the result

You might be interested in
Complete the function to return the result of the conversiondef convert_distance(miles):km = miles * 1.6 # approximately 1.6 km
AnnZ [28]

Answer:

The complete program is as follows:

def convert_distance(miles):

   km = miles * 1.6 # approximately 1.6 km in 1 mile

   return km

my_trip_miles = 55

# 2) Convert my_trip_miles to kilometers by calling the function above

my_trip_km =convert_distance(my_trip_miles) #3) Fill in the blank to print the result of the conversion

# 4) Calculate the round-trip in kilometers by doubling the result,

print("The distance in kilometers is " +str(my_trip_km))

# and fill in the blank to print the result

print("The round-trip in kilometers is " + str(my_trip_km * 2))

Explanation:

<em>The program is self-explanatory because I used the same comments in the original question.</em>

5 0
3 years ago
Which label belongs in the area marked Z? Producers Science Question
Bad White [126]
Idk dont  ask me i thank its c
5 0
3 years ago
Read 2 more answers
Im stuck in this and its a easy
Tamiku [17]

Answer:

just turn off your computer.

Explanation:

4 0
3 years ago
Read 2 more answers
Give an efficient algorithm to find all keys in a min heap that are smaller than a provided valueX. The provided valuedoes notha
OlgaM077 [116]

Answer:

Starting from root, recursively traverse the min-heap. Once we find a key with value less than our X, we know that every key in subtree of that key will be also smaller than our X. Otherwise, we should keep traversing.

Explanation:

The complexity of this algorithm will be O(N) where N is the number of keys in our min-heap.

3 0
3 years ago
PLSS HELP ASAP ILL GIVE BRAINLIEST THANKS
Svet_ta [14]
Second one i’m pretty sure
3 0
2 years ago
Other questions:
  • Sal Kan earned $3,000.00, But he is only getting $1,585.00 on his pay check to
    9·1 answer
  • Write about the future of Reliability and Security in Software Engineering.
    13·1 answer
  • Which feature of a presentation program’s interface provides a list of commands to create, format, and edit presentations?
    14·2 answers
  • In a typical e-mail address the host is
    14·1 answer
  • Sometimes when a baby is born they need to be kept in an incubator for a period of time. A manufacturer would like to design a n
    11·1 answer
  • While working with style formatting for a Microsoft Word document, when you change the text or paragraph formatting of a single
    13·1 answer
  • a. Create an Abstract class called Vehicle with abstract methods accelerate, stop, and gas, &amp; data of your choice (5 marks)
    12·1 answer
  • Write a SELECT statement that returns the same result set as this SELECT statement. Substitute a subquery in a WHERE clause for
    13·1 answer
  • There are main type of memory
    7·1 answer
  • Python;
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!