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]
3 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]3 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
? Assessment
Ksivusya [100]

Answer:

Her performance over the course of  a season.

Explanation:

An athlete is signed for a season. These days each aspect of an athlete is noted through the effective use of the best technology. However, for detailed study, one or several plays, and certainly not the second half of a game is enough. It's required to collect the details for a complete season. And that is possible, as an athlete is hired for a season. And through such a detailed data set of a complete season, we can now train a machine as well, and it will let the athlete know where she is going wrong. And thus she can improve and remove those faults from her game, and become a better athlete. And even for a coach, one complete season is required, though when he has not seen her playing before that season. It's assumed that this is her first season. All the options mentioned are good, but the best is certainly the one with complete details, and that is a complete season. The rest is good but not the best.

4 0
3 years ago
Technology can cause a drop in input costs.<br> a. True<br> b. False
Marizza181 [45]
<span>True that technology can cause a drop in input cost. In a production process, there are three kinds of cost that called input cost, which are the direct material cost, direct labor cost, and overhead cost. Technology usage can make the production process more efficient by reducing labors included in the process. This condition leads to a cost reduction.</span>
6 0
3 years ago
Read 2 more answers
Please help with this:
Tanzania [10]

Answer:

I'm not gonna give you the answer. I want you to think about this what is math, what is science, how does it help the world, and etc. These are some example questions to help.

Explanation:

5 0
2 years ago
Sino ang pinaka matalino sa math sa buong mundo​
Svetllana [295]

Answer:

lahat ng tao ay matalino kasama ka na dun kaya lang di natin ito inilalabas dahil natatamad tayo

6 0
3 years ago
Read 2 more answers
An effective problem statement ensures that
swat32
The software design effectively addresses the issues
6 0
3 years ago
Other questions:
  • What was the impact of the rise of the Japanese auto industry and the semiconductor industry in south eastern​ Asia? A. It incre
    13·1 answer
  • What are the five resources paid for by local taxes
    15·1 answer
  • Which of the following is NOT a benefit of safety and health programs?
    11·1 answer
  • The area of a square is stored in a double variable named area. write an expression whose value is length of the diagonal of the
    8·1 answer
  • SOLVE IN C:
    10·1 answer
  • All health information available on the internet is valid. <br> a. true <br> b. false
    6·1 answer
  • What will the declaration below do to its target?
    9·1 answer
  • How to get off of supervised user
    7·1 answer
  • What is the purpose of file extensions? A. They execute the mail merge function, B. They tell the operating system what kind of
    15·2 answers
  • If a citation has a volume, title, and page numbers, it is a:
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!