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
* Describe the five components of a<br> computer
LenaWriter [7]

Answer:

Computer systems consist of three components as shown in below image: Central Processing Unit, Input devices and Output devices. Input devices provide data input to processor, which processes data and generates useful information that's displayed to the user through output devices. This is stored in computer's memory.

5 0
2 years ago
Read 2 more answers
A site has been issued the IP address of 192. 168. 10. 0/24. The largest network contained 25 hosts and was given the lowest num
dimulka [17.4K]

Answer:

Explanation: The first thing to calculate is what IP addresses are used by the largest LAN. Because the LAN has 100 hosts, 7 bits must be left for host bits.

Explanation:

Explanation: The first thing to calculate is what IP addresses are used by the largest LAN. Because the LAN has 100 hosts, 7 bits must be left for host bits.

4 0
1 year ago
Search engines enable you to:A. talk to people via the computer.B. locate Web pages related to a specific subject.C. connect to
GalinKa [24]
The correct answer is B. locate Web pages related to a specific subject.

An example of a search engine is Google: it helps you find Websites with the content you're looking for.
3 0
2 years ago
output device. Vrite very short answer of the following questions. What is computer hardware? Which dovico in lini nwhich device
kirill115 [55]

Computer hardware is the physical components that a computer system requires to function.

Have a gr8 day ahead ✌️

7 0
2 years ago
Which of the following is a quality of a mixed economy?
tekilochka [14]

Answer:

Image result for Which of the following is a quality of a mixed economy? 1. Businesses have complete control of what they import. 2. Individuals have complete control of what they export. 3.Leaders determine the wages of individuals without any input from businesses. 4. Government encourages free trade of specific products.

'One main characteristic of a mixed economy is the ownership of goods by both private and government/state-owned entities. Monopolies have the potential to occur in this type of economy, but the government closely monitors this. For the economy to be mixed, the government can control some parts but not all.

Explanation:

6 0
2 years ago
Other questions:
  • Why might location be important when searching for a job?
    10·2 answers
  • Que cambiaría personalmente en esos momentos de cuarentena​
    7·1 answer
  • What is the difference between a sequential program and an event-driven program?
    9·1 answer
  • CPU BENCHMARKS are measurements used to compare performance between processors
    9·1 answer
  • Suppose I create a new kind of Java object, called "Kangaroo". Further suppose that at any given time, all instances of this new
    6·1 answer
  • What is information associated with a document to help describe that document called?
    14·1 answer
  • Which attribute defines the file name for the specific image in an image tag??
    13·1 answer
  • What is the relationship between agile teams and project requirements
    9·1 answer
  • FILL IN THE BLANK.
    10·1 answer
  • The term used to describe whereby old and new media are available via the integration of personal computers and high speed satel
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!