def ana1(w1, w2, lamb): data = load('./Result/small_prob.pk') # bot_ids = ab_traf_bot_det(data['adj_mats'], w1=10, w2=0.001, lamb=0) bot_ids = ab_traf_bot_det(data['adj_mats'], w1=w1, w2=w2, lamb=lamb) bot_ips = [data['ips'][i] for i in bot_ids] # print('bot_ips', bot_ips) ddos_ips = data['ddos_ips'] stat = get_quantitative(ddos_ips, bot_ips, data['ips'], show=True) return stat, bot_ips
# flows.txt // the normal IP Address. We can stored it separately. # this is used to get All ddos ip addresses. This tool should only deal with # SIGs. botnet data should be converted to SIGs first. def get_ips(data, format_=None): nnx = NetworkXGraph(data=data) if format_ is not None: return [format_(ip) for ip in nnx.get_vertices()] return nnx.get_vertices() # GetAdjacent Matrix ab_ids = range(200, 230) sigs = load('./Result/sigs_nx.pk') adj_mats = [nx.to_scipy_sparse_matrix(sigs[i]) for i in ab_ids] #### Identify the Pivot Nodes ###### tr = load('./Result/GCM_tr.pk') weights = tr['solution'] p_nodes = ident_pivot_nodes(adj_mats, weights, 0.8) # select *SN* Nodes together with p_nodes N = adj_mats[0].shape[0] perm = np.random.permutation(N - len(p_nodes)) SN = 100 selected_nodes = perm[:(SN - len(p_nodes))] selected_nodes = np.concatenate([selected_nodes, p_nodes]) # get Adjacent matrix for the selected subgraph
# CSV Dataset Read and Flushed """rd = ReadDataSet("Data/Dataset") rd.readCSV()""" # Create Graph and save """rd = ReadDataSet("Data/Slashdot0811") G = nx.Graph() for ln in rd.readTxt(): a, b = map(int, ln.split()) G.add_edge(a, b)""" # Save Graph """flush(G)""" # Load Graph G = load() # Print Node Contents """for item in G.nodes(data=True): print item""" # Get Friends of node node = '2014BCS072' print G.node[node] print "" pairL = ProcessNetwork(G, node) for item in pairL: print item, G.node[item] # Calculate accuracies """lst = []
def getAll(datasave=True): """ return [index, time, num1, num1delta, num2, num2delta] """ print('Local Data 수집 시작') MGLocalFetchBot.old = load('localdata.bin') #[url, num1, num2, index] bundle = [[ 'https://www.suwon.go.kr/web/safesuwon/corona/PD_index.do#none', 'body > div.layout > div > ul > li:nth-child(1) > div > div.status.clearfix > table > tbody > tr > td:nth-child(1)', 'body > div.layout > div > ul > li:nth-child(1) > div > div.status.clearfix > table:nth-child(2) > tbody > tr > td:nth-child(2)', 'body > div.layout > div > ul > li:nth-child(1) > div > div.status.clearfix > div' ], [ 'https://corona.seongnam.go.kr/', '#value01', '#value03', '#corona_page > div.corona_page_top > div > div.contents_all > span' ]] threads = [] i = 0 idx_ls = [0, 2] for data in bundle: threads.append( threading.Thread(target=MGLocalFetchBot.Fetch_local_case1, args=(data, idx_ls[i]))) i += 1 threads.append( threading.Thread(target=MGLocalFetchBot.Fetch_local_case2)) threads.append( threading.Thread(target=MGLocalFetchBot.Fetch_local_case3)) start = time.time() for x in threads: x.start() for x in threads: x.join() end = time.time() datals = [] if datasave: numls = [] print(MGLocalFetchBot.local_data) for k, v in sorted(MGLocalFetchBot.local_data.items()): datals.append(v) if datasave: if len(v) == 0: numls.append(MGLocalFetchBot.old[k]) else: numls.append([v[2], v[4]]) # print(numls) if datasave: MGLocalFetchBot.newls = numls print('Local Data 수집 끝', end - start) print(datals) return datals
# sigs_nx.pk // sigs stored in networkx format # GCM_Tr.pk // solution --> this is unecessary, we will use equal weights # flows.txt // the normal IP Address. We can stored it separately. # this is used to get All ddos ip addresses. This tool should only deal with # SIGs. botnet data should be converted to SIGs first. def get_ips(data, format_=None): nnx = NetworkXGraph(data=data) if format_ is not None: return [format_(ip) for ip in nnx.get_vertices()] return nnx.get_vertices() # GetAdjacent Matrix ab_ids = range(200, 230) sigs = load('./Result/sigs_nx.pk') adj_mats = [nx.to_scipy_sparse_matrix(sigs[i]) for i in ab_ids] #### Identify the Pivot Nodes ###### tr = load('./Result/GCM_tr.pk') weights = tr['solution'] p_nodes = ident_pivot_nodes(adj_mats, weights, 0.8) # select *SN* Nodes together with p_nodes N = adj_mats[0].shape[0] perm = np.random.permutation(N - len(p_nodes)) SN = 100 selected_nodes = perm[:(SN-len(p_nodes))] selected_nodes = np.concatenate([selected_nodes, p_nodes]) # get Adjacent matrix for the selected subgraph