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 the packet-size list and an average of the packet-size list. There are a lot of data for each time-period value. We calculate 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:
This will give
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_ip_address()) |
192.168.0.24 |
And
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:
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()) |
[[0, 10], [1, 10], [2, 1]] |
|
ip_key = '192.168.0.24' data_list = [(0, 84), (1, 84), (2, 84), (3, 84), (4, 84)] size = 3 ip = IP_address(ip_key, data_list, size) print(ip.get_freq_list()) |
[[0, 5], [1, 0], [2, 0]] |
|
ip_key = '192.168.0.2' data_list = [(33, 60), (34, 64), (34, 1500), (34, 712), (35, 52), (35, 60), (36, 52), (36, 287), (37, 52), (37, 52), (37, 52), (39, 60), (40, 643), (40, 52)] size = 5 ip = IP_address(ip_key, data_list, size) print(ip.get_freq_list()) |
[[0, 0], [1, 0], [2, 0], [3, 12], [4, 2]] |
Thanks for the question. Below is the code you will be needing Let me know if you have any doubts or if you need anything to change. Thank You !! ================================================================================================ class IP_address(): def __init__(self,key,data_list,size): self.ip_key=key self.data_list=data_list self.size=size def get_ip_address(self): return self.ip_key def get_freq_list(self): frequencies=[0 for i in range(self.size)] for data in self.data_list: index = data[0]//10 if index<self.size: frequencies[index]+=1 return [list(e) for e in zip([i for i in range(self.size)],frequencies)] ip_key = '192.168.0.2' data_list = [(33, 60), (34, 64), (34, 1500), (34, 712), (35, 52), (35, 60), (36, 52), (36, 287), (37, 52), (37, 52), (37, 52), (39, 60), (40, 643), (40, 52)] size = 5 ip = IP_address(ip_key, data_list, size) print(ip.get_freq_list())
=======================================================================================
Get Answers For Free
Most questions answered within 1 hours.