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
2. What is the name for an action performed by the VR Robot?
pychu [463]
Parameter is the answer you wanted
4 0
3 years ago
Read 2 more answers
Three types of common program errors are syntax, runtime, and logic. (5 points)
adoni [48]

Answer:

True

Explanation:

3 0
2 years ago
Read 2 more answers
True or False<br> humans shed skin in their sleep (pwease fweinds onwy answer)
eimsori [14]

Answer:

Not all people but sometimes it happens

4 0
3 years ago
Will give brainliest and good amount of points, no false answers.
nlexa [21]

The problem with the swap function is that it loses the value at the first index, as soon as it gets overwritten by the value at the second index. This happens in the first statement. To fix it, you need a helper variable.

First you're going to "park" the index at the first index in that helper variable, then you can safely overwrite it with the value at the second index. Then finally you can write the parked value to the second index:

var swap = function(array, firstIndex, secondIndex) {

let helper = array[firstIndex];

array[firstIndex]  = array[secondIndex];

array[secondIndex] = helper;

};

I hope this makes sense to you.

7 0
3 years ago
Computer design software requires __________________ to be used properly and successfully by architects.
murzikaleks [220]
<span>The answer is letter B. An arrangement of directions and related documentation that instructs a PC or how to play out an undertaking or it can mean all the product on a PC, including the applications and the working framework. I hope the answer helps. </span>
5 0
3 years ago
Read 2 more answers
Other questions:
  • A(n) _______________ CRM provides all users with the tools and information they need to fit their individual roles and preferenc
    14·1 answer
  • What’s the answer to this question?
    15·1 answer
  • Anyone here good with python coding. I have some machine learning homework which I am having a hard time with,
    12·1 answer
  • What do we call the two parts of lift that goes down a mine
    7·2 answers
  • Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards
    9·1 answer
  • What does an operating system do?
    12·1 answer
  • Microsoft Word
    15·2 answers
  • Transition words and phrase in a paragraph
    15·2 answers
  • Which of the following is primarily operated by a touchscreen?
    5·1 answer
  • What is causing the electricity prices to increase in South Africa?​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!