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
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
Get Answers For Free
Most questions answered within 1 hours.