Question

In python Please Problem We want to create a DHCP service that assigns a random, unique...

In python Please

Problem

We want to create a DHCP service that assigns a random, unique IP with subnet mask 255.0.0.0. This means the service only sets the last 3 octets of an IP. For example if the dhcp_service function is called by an IP of "192.0.0.0", it should keep the 192 and change the rest:

1. Create a dhcp_service(ip_address) function, outside of the ServerClass

2. Have request_dhcp_ip call the dhcp_service and set the ServerClass object's IP to the generated IP

_________________________

Please use this code to start

from random import randint

def dhcp_service(ip_address):
    # TODO - Write IP generation function, that generates the last 3 octets for the IP
    return

class ServerClass:

    def __init__(self):
        # DO NOT EDIT
        self.ip = "10.0.0.0"

    def request_dhcp_ip(self):
        # TODO - Call dhcp_service, set the IP to its result

Homework Answers

Answer #1

from random import randint
import random
def dhcp_service(ip_address):
# TODO - Write IP generation function, that generates the last 3 octets for the IP
assigned = '.'.join('%s'%random.randint(0, 255) for i in range(3))
first = ip_address.split('.')[0]
ip_address = first+"."+assigned
return ip_address

class ServerClass:

def __init__(self):
# DO NOT EDIT
self.ip = "10.0.0.0"

def request_dhcp_ip(self):
# TODO - Call dhcp_service, set the IP to its result
self.ip = dhcp_service(self.ip)

# creating object and calling to get unique IP on every call
s = ServerClass()
s.request_dhcp_ip()
s.ip

Know the answer?
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
Similar Questions
Python Problem 1 Create a function, biggest_ip_sum, outside of the ServerClass class, that: 1. Takes two...
Python Problem 1 Create a function, biggest_ip_sum, outside of the ServerClass class, that: 1. Takes two ServerClass objects 2. Sums the octets of the IP together (example 127.0.0.1 = 127+0+0+1 = 128) 3. Returns the larger number Example: server_one = ServerClass("127.0.0.1") server_two = ServerClass("192.168.0.1") result = biggest_ip_sum(server_one, server_two) print(result) In the example above, result will be 361. _________________________________ Problem 1 Here is the code to start with class ServerClass: """ Server class for representing and manipulating servers. """ def __init__(self,...
Please create a python module named homework.py and implement the functions outlined below. Below you will...
Please create a python module named homework.py and implement the functions outlined below. Below you will find an explanation for each function you need to implement. When you are done please upload the file homework.py to Grader Than. Please get started as soon as possible on this assignment. This assignment has many problems, it may take you longer than normal to complete this assignment. This assignment is supposed to test you on your understanding of reading and writing to a...
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21,...
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21, all players who are still standing win. But the players that are not standing have already lost. If the Dealer does not go over 21 but stands on say 19 points then all players having points greater than 19 win. All players having points less than 19 lose. All players having points equal to 19 tie. The program should stop asking to hit if...
Coding in Python Add radio button options for filing status to the tax calculator program of...
Coding in Python Add radio button options for filing status to the tax calculator program of Project 1. The user selects one of these options to determine the tax rate. The Single option’s rate is 20%. The Married option is 15%. The Divorced option is 10%. The default option is Single. Be sure to use the field names provided in the comments in your starter code. ================== Project 1 code: # Initialize the constants TAX_RATE = 0.20 STANDARD_DEDUCTION = 10000.0...
PYTHON : Create a Email Address Parser (* Please do make comments*) Often times, you may...
PYTHON : Create a Email Address Parser (* Please do make comments*) Often times, you may be given a list of raw email addresses and be asked to generate meaningful information from such a list. This project involves parsing such a list and generating names and summary information from that list. The script, eparser.py, should: Open the file specified as the first argument to the script (see below) Read the file one line at a time (i.e., for line in...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT