Esempio n. 1
0
    def load_file(self):
        filename = self.open_file()
        print(filename)
        if filename == "":
            show_text = "取消读取文件"
            self.change_show_text(show_text)
            return
        show_text = "正在打开" + filename + " \n最大读取包数:" + str(self.packet_load_num)
        self.change_show_text(show_text)
        self.root.update()
        this_pcap_file = Pcap_class.build_pcap(filename, self.packet_load_num)
        show_text = "成功创建Pcap类,共含" + str(len(this_pcap_file.get_packets())) + "个流量包"
        self.change_show_text(show_text)
        self.load_in_flag = 1
        save_data.clear_all_table()
        show_text = "清空临时表完毕"
        self.change_show_text(show_text)
        save_data.save_data(this_pcap_file)
        show_text = "填写临时表完毕"
        self.change_show_text(show_text)
        self.static_datas = statistic_analysis.statistic_analysis_entrance()
        show_text = "统计分析完成"
        self.change_show_text(show_text)
        self.fill_data_table(self.static_datas)


        width = int(self.maxWidth / 3)
        height = self.maxHeight - 120
        labels = [u'TCP', u'UDP', u'DNS',u'HTTP', u'HTTPS']
        protocol_adjust_list = copy.deepcopy(self.static_datas[-2])
        protocol_adjust_list[0] = protocol_adjust_list[0] - protocol_adjust_list[3] - protocol_adjust_list[4]
        protocol_adjust_list[1] = protocol_adjust_list[1] - protocol_adjust_list[2]
        statistic_analysis.draw_pie(protocol_adjust_list, labels, "protocol")
        self.photo_main = self.Load_img('protocol_pie.png', width, height)
        self.label_image.config(image=self.photo_main)
def create_test_data():
    number_for_packets = 150
    # 关闭文件
    filename = "D:/Projects/Virtual_Analysis_changing/pcaps/weixin_big_2"
    filename2 = "D:/Projects/Virtual_Analysis_changing/pcaps/QQ"
    filename3 = "D:/Projects/Virtual_Analysis_changing/pcaps/xunlei_1"
    my_pcap_file = Pcap_class.build_pcap(filename + ".pcap", number_for_packets)
    my_pcap_file_2 = Pcap_class.build_pcap(filename2 + ".pcap", number_for_packets)
    my_pcap_file_3 = Pcap_class.build_pcap(filename3 + ".pcap", number_for_packets)
    packets = my_pcap_file.get_packets()
    packets2 = my_pcap_file_2.get_packets()
    packets3 = my_pcap_file_3.get_packets()

    packet_list = []
    packet_num = 0
    for packet in packets:
        data = distribution_collect(packet)
        # print(data)
        packet_list.append(data)
        packet_num += 1
        if packet_num > number_for_packets:
            break
    for packet in packets2:
        data = distribution_collect(packet)
        # print(data)
        packet_list.append(data)
        packet_num += 1
        if packet_num > number_for_packets * 2:
            break
    for packet in packets3:
        data = distribution_collect(packet)
        # print(data)
        packet_list.append(data)
        packet_num += 1
        if packet_num > number_for_packets * 3:
            break
    return packet_list
 def load_file(self):
     filename = self.open_file()
     print(filename)
     if filename == "":
         show_text = "取消读取文件"
         self.change_show_text(show_text)
         return
     show_text = "正在打开" + filename + " \n最大读取包数:" + str(self.packet_load_num)
     self.change_show_text(show_text)
     self.root.update()
     this_pcap_file = Pcap_class.build_pcap(filename, self.packet_load_num)
     show_text = "成功创建Pcap类,共含" + str(len(this_pcap_file.get_packets())) + "个流量包"
     self.change_show_text(show_text)
     save_data.clear_all_table()
     show_text = "清空临时表完毕"
     self.change_show_text(show_text)
     save_data.save_data(this_pcap_file)
     show_text = "填写临时表完毕"
     self.change_show_text(show_text)
     static_datas = statistic_analysis.statistic_analysis_entrance()
     show_text = "统计分析完成"
     self.change_show_text(show_text)
     print(static_datas)
     self.fill_data_table(static_datas)
Esempio n. 4
0
    mac_str = mac_str[0:len(mac_str) - 1]
    return mac_str


def ip_process(ip_int):
    ip_raw_str = hex(ip_int)
    ip_raw_str = ip_raw_str[2:]
    while (8 - len(ip_raw_str)) > 0:
        ip_raw_str = "0" + ip_raw_str
    ip_str = ""
    i = 0
    while i < 8:
        temp_str = str(int(ip_raw_str[i:2 + i], 16))
        ip_str = ip_str + temp_str + "."
        i += 2
    ip_str = ip_str[0:len(ip_str) - 1]
    return ip_str


if __name__ == '__main__':
    db_helper.clear_table("basic_part_data")
    db_helper.clear_table("tcp_part_data")
    db_helper.clear_table("http_part_data")
    db_helper.clear_table("udp_part_data")
    db_helper.clear_table("https_part_data")
    db_helper.clear_table("dns_part_data")
    my_pcap_file = Pcap_class.build_pcap("necurs2.pcap")
    print("PcapFile analysing complete")
    save_data(my_pcap_file)
    print("Done")
Esempio n. 5
0
    file = open("test2.model", "wb")
    # # 把模型写入到文件中
    pickle.dump(clf, file)
    # # 关闭文件
    file.close()
    '''

    #'''
    # 以读二进制的方式打开文件
    file = open("test2.model", "rb")
    # 把模型从文件中读取出来
    anova_svm = pickle.load(file)
    # 关闭文件
    file.close()
    filename = "D:/Projects/Virtual_Analysis_changing/weixin_big_2"
    my_pcap_file = Pcap_class.build_pcap(filename + ".pcap", 150)
    packets = my_pcap_file.get_packets()
    packet_list = []
    packet_num = 0
    for packet in packets:
        data = distribution_collect(packet)
        #print(data)
        packet_list.append(data)
        packet_num += 1
        if packet_num > 150:
            break
    test_data = pd.DataFrame(
        packet_list,
        columns=[
            'length', 'Src_port', 'Dst_port', 'data_01', 'data_02', 'data_03',
            'data_04', 'data_05', 'data_06', 'data_07', 'data_08', 'data_09',
    # # 把模型写入到文件中
    pickle.dump(clf, file)
    # # 关闭文件
    file.close()

    '''
    # 以读二进制的方式打开文件
    file = open("app.model", "rb")
    # 把模型从文件中读取出来
    anova_svm = pickle.load(file)
    # 关闭文件
    file.close()
    filename = "D:/Projects/Virtual_Analysis_changing/weixin_big_2"
    filename2 = "D:/Projects/Virtual_Analysis_changing/QQ"
    filename3 = "D:/Projects/Virtual_Analysis_changing/xunlei_1"
    my_pcap_file = Pcap_class.build_pcap(filename + ".pcap", 50)
    my_pcap_file_2 = Pcap_class.build_pcap(filename2 + ".pcap", 50)
    my_pcap_file_3 = Pcap_class.build_pcap(filename3 + ".pcap", 50)
    packets = my_pcap_file.get_packets()
    packets2 = my_pcap_file_2.get_packets()
    packets3 = my_pcap_file_3.get_packets()

    packet_list = []
    packet_num = 0
    for packet in packets:
        data = distribution_collect(packet)
        #print(data)
        packet_list.append(data)
        packet_num += 1
        if packet_num > 50:
            break
Esempio n. 7
0
        mac_str = mac_str + mac_raw_str[i:2 + i] + ":"
        i += 2
    mac_str = mac_str[0:len(mac_str) - 1]
    return mac_str


def ip_process(ip_int):
    ip_raw_str = hex(ip_int)
    ip_raw_str = ip_raw_str[2:]
    while (8 - len(ip_raw_str)) > 0:
        ip_raw_str = "0" + ip_raw_str
    ip_str = ""
    i = 0
    while i < 8:
        temp_str = str(int(ip_raw_str[i:2 + i], 16))
        ip_str = ip_str + temp_str + "."
        i += 2
    ip_str = ip_str[0:len(ip_str) - 1]
    return ip_str


if __name__ == '__main__':
    db_helper.clear_table("basic_part_data")
    db_helper.clear_table("tcp_part_data")
    db_helper.clear_table("http_part_data")
    db_helper.clear_table("udp_part_data")
    my_pcap_file = Pcap_class.build_pcap("test22.pcap")
    print("PcapFile analysing complete")
    save_data(my_pcap_file)
    print("Done")