Beispiel #1
0
def beacon_process():
    bc_mac_list = []  # 맥주소 리스트
    bc_mac_pkt_dc = {}  # key: wlan.sa , value: becon-frame(2-D list)
    bc_mac_csv_dc = {}  # key: wlan.sa, value: csv file names(list)
    bc_csv_fm_list = []  # becon-frame feature csv file names(list)
    ap_dic = {}  # key : (ssid,MAC Address), value: label

    # 지정한 ap 기기만 필터하여 beacon.csv에 저장
    collect.device_filter_testcase(filePath.learn_csv_beacon_path,
                                   mode="beacon",
                                   train=True)

    # 맥주소 추출
    bc_mac_list = prePro.extract_macAddress(filePath.learn_csv_beacon_path)

    # 맥주소 정렬
    bc_mac_list.sort()

    # beacon 디렉토리 생성
    file.make_Directory(filePath.beacon_path)

    # 맥주소별 디렉토리 생성
    file.make_macDirectory(filePath.beacon_path, bc_mac_list)

    #time별 csv파일 생성, 3분간격으로 csv파일 생성
    bc_mac_csv_dc = file.make_macCsvFile(filePath.beacon_path, bc_mac_list, 3)

    # 맥별 becon-frame 데이터 추출
    bc_mac_pkt_dc = prePro.extract_packetLine(filePath.learn_csv_beacon_path,
                                              bc_mac_list)

    # time별 csv파일에 데이터 저장
    file.save_csvFile(filePath.beacon_path, bc_mac_pkt_dc, 3)

    # wlan.fixed.timestamp 전처리
    prePro.beacon_prepro(bc_mac_csv_dc)

    # featuremodel.csv 파일 생성
    for mac_name in bc_mac_list:
        file.make_csvFeature(filePath.beacon_path, mac_name, frame="beacon")

    #bc_csv_fm_list = file.init_beacon_FeatureFile(bc_mac_csv_dc) # featuremodel.csv파일에 데이터 저장
    # featuremodel.csv파일에 특징 데이터 저장
    bc_csv_fm_list = file.init_beacon_FeatureFile(bc_mac_csv_dc)

    # 학습데이터 생성
    # x_train : [[clock skew, rss, channel, ssid, wlan.sa], ..., [...]]
    # y_train : [[ssid, wlan.sa], ..., [...]]
    # ap_dic : "label" : [ssid, wlan.sa], ex) "0" : ["carlynne","ff:ff:ff:ff:ff:ff"]
    x_train, y_train, ap_dic = machine_learn.get_becon_train_data(
        bc_csv_fm_list)

    # AP식별 모델 생성
    ap_model = machine_learn.random_forest_model(x_train, y_train)

    # AP식별 모델 저장
    machine_learn.save_model(ap_model, "ap_model.pkl")

    # AP식별 레이블 딕셔너리 저장
    machine_learn.save_label_dic(ap_dic, "ap_label.json")
Beispiel #2
0
def proReq_process():
    mac_list = [
    ]  # wlan.sa list, list["fe:e6:1a:f1:d6:49", ... ,"f4:42:8f:56:be:89"]
    feat_x_train = []  # random forest model x_train
    feat_y_train = []  # random forest model y_train
    device_dic = {}  # key:label value: mac address, "0" : "ff:ff:ff:ff"
    label = 0  # 무선단말 레이블

    # 지정한 무선단말 기기만 필터하여 probe.csv에 저장
    collect.device_filter_testcase(filePath.learn_csv_probe_path,
                                   mode="probe",
                                   train=True)

    # 맥주소 추출
    mac_list = prePro.extract_macAddress(filePath.learn_csv_probe_path)

    # 맥주소 오름차순 정렬
    mac_list.sort()

    #probe.csv 파일 읽기
    data = probe.read_probe(filePath.learn_csv_probe_path)

    #probe 디렉토리 생성
    file.make_Directory(filePath.probe_path)

    #data를 참조하여 맥별로 probe-request 데이터를 나눈다.
    probe.separate_probe(mac_list, data)

    # 맥별로 FeatureModel.csv 파일을 생성한다.
    for mac_name in mac_list:
        file.make_csvFeature(filePath.probe_path, mac_name, "seq")

    # 맥별로 label 할당
    for mac in mac_list:
        device_dic.update({label: mac})
        label += 1

    # 맥별 featureModel.csv 파일에 특징 데이터(delta seq no, length, label)를 추가한다.
    fm_name_list = file.init_seq_FeatureFile(data, mac_list,
                                             filePath.probe_path, device_dic)

    # 학습 데이터 생성
    # feat_x_train : [[delta seq no, length], ..., [...]]
    # feat_y_train : [0,0,1,1, ..., 2]
    feat_x_train, feat_y_train = machine_learn.get_proReq_train_data(
        fm_name_list)

    # 무선단말 식별 모델 생성
    device_model = machine_learn.random_forest_model(feat_x_train,
                                                     feat_y_train)

    # 무선단말 식별 모델 저장
    machine_learn.save_model(device_model, "device_model.pkl")

    # 무선단말 식별 레이블 딕셔너리 저장
    machine_learn.save_label_dic(device_dic, "device_label.json")
Beispiel #3
0
def proReq_createTestset():
    mac_list = [
    ]  # wlan.sa list, list["fe:e6:1a:f1:d6:49", ... ,"f4:42:8f:56:be:89"]
    feat_x_train = []  # random forest model x_train
    feat_y_train = []  # random forest model y_train
    device_dic = {}  # key:label value: mac address
    label = 0

    #collect.device_filter(filePath.test_csv_probe_path,mode="probe") # 지정한 기기만 필터하여 probe.csv에 저장
    collect.device_filter_testcase(filePath.test_csv_probe_path,
                                   mode="probe",
                                   train=False)  # 지정한 기기만 필터하여 probe.csv에 저장

    mac_list = prePro.extract_macAddress(
        filePath.test_csv_probe_path)  # 맥주소 추출

    data = probe.read_probe(filePath.test_csv_probe_path)

    file.make_Directory(filePath.probe_test_path)

    probe.separate_probe(mac_list, data, csvname="probe_test")

    # make feature csv file for each the wlan.sa
    for mac_name in mac_list:
        file.make_csvFeature(filePath.probe_test_path, mac_name, "seq")

    device_dic = machine_learn.load_label_dic("device_label.json")

    fm_name_list = file.init_seq_FeatureFile(
        data,
        mac_list,
        filePath.probe_test_path,
        device_dic,
        csvname="probe_test")  #a dd the feature data

    feat_x_train, feat_y_train = machine_learn.get_proReq_train_data(
        fm_name_list)  # 학습 데이터 생성

    feat_y_train = np.reshape(feat_y_train,
                              (-1, 1))  # [0,1,2] => [[0],[1],[2]]

    ident_mac_list = []
    for item in feat_y_train:
        if str(item[0]) not in device_dic.keys():
            ident_mac_list.append("unknown terminal")
        else:
            ident_mac_list.append(device_dic[str(item[0])])

    #[[delta seq no, length, label]...,] 형식으로 생성
    for x, y, z in zip(feat_x_train, feat_y_train, ident_mac_list):
        x.extend([z])
        x.extend(y)

    return feat_x_train
Beispiel #4
0
def beacon_createTestset():
    bc_mac_list = []  # 맥주소 리스트
    bc_mac_pkt_dc = {}  # key: wlan.sa , value: becon-frame(2-D list)
    bc_mac_csv_dc = {}  # key: wlan.sa, value: csv file names(list)
    bc_csv_fm_list = []  # becon-frame feature csv file names(list)
    ap_dic = {}  # key : (ssid,MAC Address), value: label

    collect.device_filter_testcase(filePath.test_csv_beacon_path,
                                   mode="beacon",
                                   train=False)  # 지정한 기기만 필터하여 probe.csv에 저장

    bc_mac_list = prePro.extract_macAddress(
        filePath.test_csv_beacon_path)  # 맥주소 추출

    bc_mac_list.sort()  # 맥주소 정렬

    file.make_Directory(filePath.beacon_test_path)

    file.make_macDirectory(filePath.beacon_test_path,
                           bc_mac_list)  # 맥주소별 디렉토리 생성

    bc_mac_csv_dc = file.make_macCsvFile(filePath.beacon_test_path,
                                         bc_mac_list, 3)  #time별 csv파일 생성

    bc_mac_pkt_dc = prePro.extract_packetLine(filePath.test_csv_beacon_path,
                                              bc_mac_list)  #becon-frame데이터 추출

    file.save_csvFile(filePath.beacon_test_path, bc_mac_pkt_dc,
                      3)  # time별 csv파일에 데이터 저장

    prePro.beacon_prepro(bc_mac_csv_dc)  # wlan.fixed.timestamp 전처리

    # featuremodel.csv 파일 생성
    for mac_name in bc_mac_list:
        file.make_csvFeature(filePath.beacon_test_path,
                             mac_name,
                             frame="beacon")

    bc_csv_fm_list = file.init_beacon_FeatureFile(
        bc_mac_csv_dc,
        becon_path=filePath.beacon_test_path)  # featuremodel.csv파일에 데이터 저장

    ap_label = machine_learn.load_label_dic("ap_label.json")

    x_train, y_train = machine_learn.get_becon_test_train_data(
        bc_csv_fm_list, ap_label)  # 테스트 데이터 생성

    #[[clock skew, channel, rss, duration, ssid, mac address, label]...[...]] 형식 생성
    for x, y in zip(x_train, y_train):
        x.append(y)

    return x_train
Beispiel #5
0
def save_separated_probe(dfs,savepath):
    filename = 1
    paths = []
    devs = []
    for df in dfs:
        if len(df) >= 100:  # probe request data가 100개 이상 수집된 단말만 분류 csv 파일 생성
            path = savepath+"dev{}/".format(filename)
            dev_name = "dev{}".format(filename)       # dev1.csv
            
            devs.append(dev_name)                     # [dev1.csv, dev2.csv, ..., devn.csv]
            paths.append(path)                        # dev 저장 디렉토리 경로 저장
            
            file.make_Directory(path)                 # 단말 디렉토리 생성
            df.to_csv(path+dev_name+".csv", sep=',', na_rep='', index=False)
            filename += 1

    return paths, devs
Beispiel #6
0
def proReq_process():

    # step1 단말 분류
    data = read_probe(filePath.learn_csv_probe_path)

    data = make_nullProReq(data)                     # null probe request 생성, length 필드 생성

    dfs = separate_probe(data)                       # probe request를 단말별로 분류

    file.make_Directory(filePath.probe_path)         # probe 디렉토리 생성

    dev_path ,devs = save_separated_probe(dfs,filePath.probe_path) # 분류된 단말들을 csv 파일 형태로 each 저장

    for path, dev in zip(dev_path, devs): # path : ex) probe/dev1/
        # step2 단말 시퀀스 번호 전처리
        time_path = path+"time_separated/"
        file.make_Directory(time_path)
        time_names = separate_time_probe(path,dev, time_path)

        # step3 feature 추출 및 저장
        featured_path = path+"featured/"
        file.make_Directory(featured_path)
        write_feature(time_names,dev,featured_path)