In: Computer Science
python
Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following
For example, consider the following code fragment:
ip_key = '192.168.0.24' data_list =[(0, 84), (1, 84), (2, 84), (3, 84), (4, 84), (5, 84), (6, 84), (7, 84), (8, 84), (9, 84), (10, 84), (11, 84), (12, 84), (13, 84), (14, 84), (15, 84), (16, 84), (17, 84), (18, 84), (19, 84), (20, 84)] size = 3 ip = IP_address(key, data_list, size)
The data_list contains a list of tuple objects. Each tuple consists of the time-period value and the packet-size. You should summarize this list and create a frequency list, a sum of packet-size list and an average of packet-size list. There are a lot of data for each time-period value. We calculates the total number of bytes that the source host sent for each 10-second interval. For example: the above data_list will be divided into 3 groups, such as (0-9 second), (10-19 second) and (20-29 second)
Therefore, the IP_address object should contain:
We will set up the IP_address class step by step. You are required to set up the constructor and the get_ip_address() in this question. Continue from the previous question, modify the following in the IP_address class. :
For example, consider the following code fragment:
ip_key = '192.168.0.24' data_list =[(0, 84), (1, 84), (2, 84), (3, 84), (4, 84), (5, 84), (6, 84), (7, 84), (8, 84), (9, 84), (10, 84), (11, 84), (12, 84), (13, 84), (14, 84), (15, 84), (16, 84), (17, 84), (18, 84), (19, 84), (20, 84)] size = 3 ip = IP_address(key, data_list, size)
The data_list contains a list of tuple objects.
Therefore, the IP_address object should contain:
For example:
Test | Result |
---|---|
ip_key = '192.168.0.24' data_list =[(0, 84), (1, 84), (2, 84), (3, 84), (4, 84), (5, 84), (6, 84), (7, 84), (8, 84), (9, 84), (10, 84), (11, 84), (12, 84), (13, 84), (14, 84), (15, 84), (16, 84), (17, 84), (18, 84), (19, 84), (20, 84)] size = 3 ip = IP_address(ip_key, data_list, size) print(ip.get_freq_list()) print(ip.get_ip_address()) |
[[0, 10], [1, 10], [2,1] 192.168.0.24 |
class IP_address():
def __init__(self,ip_add,data,size):#Construction of the
Class
self.ip_add = ip_add
self.data = data
self.size = size #End of Assigning Parameters to Class Level
Variables
self.l_list = [self.data[i:i+10] for i in range(0, len(self.data),
10)] #ReCreating the List of lists each of size 10
self.sum_list = [] #List of Sum of Packets
for i in self.l_list:
sum = 0
for j in range(len(i)):
sum+=i[j][1]
self.sum_list.append(sum)
self.avg_list = [] #Average of the Packets of Each list of 10
Tuples
for i in range(len(self.sum_list)):
l_size = len(self.l_list[i])
avg = self.sum_list[i]/l_size
self.avg_list.append(avg)
self.feq_list = []
for f_list in self.l_list:
self.feq_list.append(str(len(f_list)))
def get_feq_list(self): #Function for Freqency List and List of
Frequencies for Each List of 10 Tuples
sent_list = []
for i in range(len(self.feq_list)):
sent_list.append([i,self.feq_list[i]])
return sent_list
def get_ip_address(self):#Function for Get IP
return self.ip_add
ip = "192.168.0.24"
data = [(0, 84), (1, 84), (2, 84), (3, 84), (4, 84), (5, 84), (6,
84), (7, 84), (8, 84), (9, 84),(10, 84), (11, 84), (12, 84), (13,
84), (14, 84), (15, 84), (16, 84), (17, 84),(18, 84), (19, 84),(20,
84)]
size = 3
print(type(data))
a = IP_address(ip,data,size)
print(a.feq_list)
''' If you want to Call the List you can Use a.avg_list,
a.feq_list will Print the Data of those Lists..'''
Thank You... :)