Question

Using Python3, how can you print out the subnet mask when it is given in slash...

Using Python3, how can you print out the subnet mask when it is given in slash notation? For example, a user types in /24 (do not worry about the slash). How would you convert that to binary? For example this would be written as 11111111.11111111.11111111.00000000. Please note, the user can change the number so do not hard code. The number can be any number from 1-32

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def getOctet(n):
    if(n<0):
        n = 0
    return "1"*n+"0"*(8-n)

if __name__ == '__main__':
    n = int(input("subnet mask: "))
    result = ""
    for i in range(4):
        if(n>8):
            result += getOctet(8)
        else:
            result += getOctet(n)
        result = result +"."
        n = n - 8
    result = result[:-1]
    print(result)

Add a comment
Know the answer?
Add Answer to:
Using Python3, how can you print out the subnet mask when it is given in slash...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For this assignment you will explore subnet addresses, host addresses and direct broadcast addresses. You will...

    For this assignment you will explore subnet addresses, host addresses and direct broadcast addresses. You will be provided an IP addresses and then asked to answer questions related to the IP. In this assignment, first we explain how to find the subnet address for each subnet, the range of host addresses, and the direct broadcast address. Then you will be asked to do a similar exercise by yourself. Assume that you have been assigned the 192.168.1.0/24 network. You need to...

  • Assume that you have been assigned 202.145.22.0/29 How many bits are borrowed to create the subnet...

    Assume that you have been assigned 202.145.22.0/29 How many bits are borrowed to create the subnet field? 5 bits What is the maximum number of subnets that can be created with this number of bits? 2^5=32 How many bits can be used to create the host space? 32 bits, 5bits to define the subnets. 27 bits for the host space. What is the maximum number of host addresses available per subnet? 3 bits for host space What is the subnet...

  • Please help me this chart with an explanation. Thanks Practice Calculating Subnet Masks Complete the blank...

    Please help me this chart with an explanation. Thanks Practice Calculating Subnet Masks Complete the blank cells in the table below based on the facts provided. The charts on pages 88 -89 may be helpful for this exercise. If you use the charts -think about the subnet mask, how the number of host bits are calculated and the resulting number of hosts. The chart already has factored in reducing the number of hosts by 2. The first and last host...

  • A.10 TestOut Linux Pro Objective 9: Network and Print Configuration Management, All Questions Question 6 of 6 Time spent: 1:4 Mark this question for review To answer this question, complete the l...

    A.10 TestOut Linux Pro Objective 9: Network and Print Configuration Management, All Questions Question 6 of 6 Time spent: 1:4 Mark this question for review To answer this question, complete the lab using information below. Launch Lab You did not complete the lab correcty You need to temporarily connect to a different network. You need to change the IP configuration manually for the enso network interface. You also need to add a new default gateway for this network so you...

  • write programs with detailed instructions on how to execute. code is java What you need to...

    write programs with detailed instructions on how to execute. code is java What you need to turn in: You will need to include an electronic copy of your report (standalone) and source code (zipped) of your programs. All programming files (source code) must be put in a zipped folder named "labl-name," where "name" is your last name. Submit the zipped folder on the assignment page in Canvas; submit the report separately (not inside the zipped folder) as a Microsoft Word...

  • write codes and give detailed explanation of how to execute. What you need to turn in:...

    write codes and give detailed explanation of how to execute. What you need to turn in: You will need to include an electronic copy of your report (standalone) and source code (zipped) of your programs. All programming files (source code) must be put in a zipped folder named "labl-name," where "name" is your last name. Submit the zipped folder on the assignment page in Canvas; submit the report separately (not inside the zipped folder) as a Microsoft Word or PDF...

  • (1) Computer hosts usually have two addresses, an Internet Protocol (IP) address and an Ethernet Media...

    (1) Computer hosts usually have two addresses, an Internet Protocol (IP) address and an Ethernet Media Access Control (MAC) address. For the benefit of humans, the IP address is normally represented as a dotted decimal notation, such as 192.168.10.2. Each of the decimal octets in the address or a mask can be converted to 8 binary bits. Remember that the computer only understands binary bits. If all 4 octets were converted to binary, how many bits would there be? (2)...

  • Write a C program that prompts the user to enter a series of integers that represent...

    Write a C program that prompts the user to enter a series of integers that represent a coded message. I have given you the decoder program so that you can see how it is written using array notation. Your assignment is to convert the code to a program that uses only pointers and pointer math. Your program must use pointer notation and pointer math (i.e. no array index notation other than in the declaration section, no arrays of pointers and...

  • An IP address is a 32-bit number that uniquely identifies a host (computer or other device,...

    An IP address is a 32-bit number that uniquely identifies a host (computer or other device, such as a printer or router) on a TCP/IP network. IP addresses are normally expressed in dotted-decimal format, with four numbers separated by periods, such as 192.168.123.132. To understand how subnet masks are used to distinguish be- tween hosts, networks, and subnetworks, examine an IP address in binary notation. For example, the dotted-decimal IP address 192.168.123.132 is (in binary notation) the 32 bit num-...

  • The rule will be for hours up to 40, calculate pay using the rate entered; for...

    The rule will be for hours up to 40, calculate pay using the rate entered; for any hours above 40, calculate pay as (1.5 * rate). Name your function to compute pay (hours, rate) and use the function to do the computation. You still want to prompt the user for hours and rate OUTSIDE of your function. Name these variables "h" for hours, and "r" for rate: h = float(input('How many hours?: ')) r = float(input('What is your hourly rate?:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT