Python
Design a class named IP_address to represent IP address objects. The IP_address class 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:
And
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 object should contain:
For example:
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_avg_list()) |
[[0, 84.0], [1, 0], [2, 0]] |
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_avg_list()) |
[[0, 84.0], [1, 84.0], [2, 84.0]] |
class IP_address:
def __init__(self,ip_key,data_list,size):
self.ip_key=ip_key;
self.data_list=data_list;
self.size=size;
def get_ip_address(self):
return self.ip_key;
def get_sum_list(self):
sum_list=[];
for i in range(1,size+1):
sumj=0;
for j in range(0+(10*(i-1)),10*i):
for data in self.data_list:
if(j==data[0]):
sumj=sumj+data[1];
break;
sum_list.append(sumj);
return sum_list;
def get_avg_list(self):
avg_list=[];
for i in range(1,size+1):
avgj=0;
sumj=0;
n=0;
for j in range(0+(10*(i-1)),10*i):
for data in self.data_list:
if(j==data[0]):
sumj=sumj+data[1];
n=n+1;
break;
if(n!=0):
avg_list.append((i-1,sumj/n));
else:
avg_list.append((i-1,sumj));
return avg_list;
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("sum list");
print(ip.get_sum_list());
print("average list");
print(ip.get_avg_list());
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("sum list");
print(ip.get_sum_list());
print("average list");
print(ip.get_avg_list());
Expected output:
Get Answers For Free
Most questions answered within 1 hours.