Exemplo n.º 1
0
def ftp():
    if FTP_TIMETABLE_FILE != "":
        running_time_list_random, running_time_list_ordered = get_running_time(
            FTP_TIMETABLE_FILE)
        if running_time_list_random == None:
            print("no time interval matched current time")
            return

        for running_time in running_time_list_random:
            # Get the current time
            current_time = time_process.get_current_time()
            print(current_time, running_time)
            while (not time_process.compare_t2t(current_time, running_time)):
                sleep(1)
                current_time = time_process.get_current_time()

            # Get a random user from the list
            username, passwd = get_random_user(ftp_users)
            print(username, passwd)
            if ftp_actions.connect(FTP_SERVER, username, passwd) == 0:
                ftp_actions.get_file(download_dir)
                clean_dir(download_dir)
                ftp_actions.quit_session()
    else:
        for i in range(0, NUM_CONN):
            now = time.time()
            username, passwd = get_random_user(ftp_users)
            if ftp_actions.connect(FTP_SERVER, username, passwd) == 0:
                ftp_actions.get_file(download_dir)
                clean_dir(download_dir)
                ftp_actions.quit_session()
            then = time.time()
            print(then - now)
Exemplo n.º 2
0
def intranet():
    count = 0
    count_https = 0
    tmp = ""
    if INTRANET_TIMETABLE_FILE != "":
        running_time_list_random, running_time_list_ordered = get_running_time(
            INTRANET_TIMETABLE_FILE)
        print(running_time_list_random)
        if (len(running_time_list_ordered) == 0):
            print("no time interval matched current time")
            return

        # Calculate http and https connection
        total_cnx = len(running_time_list_random)
        https_cnx = int(total_cnx * RATIO_HTTPS)

        current_time = time_process.get_current_time()
        # If current time is earlier than the interval
        while (not time_process.compare_t2t(current_time,
                                            running_time_list_random[0])):
            sleep(1)
            current_time = time_process.get_current_time()

        # If current time is in the interval already, then only excuse connections
        # which are later than the current time
        while True:
            # Get current time
            current_time = time_process.get_current_time()
            #print("current_time:" + current_time)
            # If the current time is out of interval, break
            if (time_process.compare_t2t(current_time,
                                         running_time_list_random[-1])):
                break
            # If current time is in the running_time_list_random, run
            if current_time in running_time_list_random and current_time != tmp:
                tmp = current_time
                count += 1
                # Get http or https connection randomly
                if count_https < https_cnx:
                    k = random.randint(0, 1)
                    if k == 0:  # HTTP connection
                        #http_actions.read_event("http", intranet_http_site_list, intranet_https_site_list)
                        #http_actions.read_event("http", intranet_http_site_list, intranet_https_site_list)
                        http_actions.read_event(HTTP_SERVER, "http")
                        http_actions.read_event(HTTP_SERVER, "http")
                    else:  # HTTPS connection
                        http_actions.read_event(HTTP_SERVER, "https")
                        http_actions.read_event(HTTP_SERVER, "https")
                        count_https += 1
                else:
                    http_actions.read_event(HTTP_SERVER, "http")
                    http_actions.read_event(HTTP_SERVER, "http")
            # If not, sleep one sec and check again
            else:
                sleep(1)
        print(count)
    else:
        for i in range(0, NUM_CONN):
            http_actions.read_event(HTTP_SERVER, "https")
Exemplo n.º 3
0
def smtp():
    send_type = ["group", "random", "broadcast"]
    if SENDMAIL_TIMETABLE_FILE != "":
        running_time_list_random, running_time_list_ordered = get_running_time(
            SENDMAIL_TIMETABLE_FILE)
        if running_time_list_random == None:
            print("no time interval matched current time")
            return

        for running_time in running_time_list_random:
            print(running_time)

        num_cxn = len(running_time_list_random)

        num_conn_group = rand_funcs.float_to_int(num_cxn * 0.6)
        num_conn_rand = rand_funcs.float_to_int(num_cxn * 0.3)
        num_conn_brc = rand_funcs.float_to_int(num_cxn * 0.1)

        num_group_temp = num_conn_group
        num_rand_temp = num_conn_rand
        num_brc_temp = num_conn_brc

        for running_time in running_time_list_random:
            # Get the current time
            current_time = time_process.get_current_time()
            while (not time_process.compare_t2t(current_time, running_time)):
                sleep(1)
                current_time = time_process.get_current_time()
            num_group_temp, num_rand_temp, num_brc_temp = one_send_email(
                send_type, num_group_temp, num_rand_temp, num_brc_temp)

    else:
        num_conn_group = rand_funcs.float_to_int(NUM_CONN * 0.6)
        num_conn_rand = rand_funcs.float_to_int(NUM_CONN * 0.3)
        num_conn_brc = rand_funcs.float_to_int(NUM_CONN * 0.1)

        num_group_temp = num_conn_group
        num_rand_temp = num_conn_rand
        num_brc_temp = num_conn_brc

        num_try = 0
        for i in range(0, NUM_CONN):
            num_group_temp, num_rand_temp, num_brc_temp = one_send_email(
                send_type, num_group_temp, num_rand_temp, num_brc_temp)
Exemplo n.º 4
0
def livestream():
    count = 0
    tmp = ""
    if LIVESTR_TIMETABLE_FILE != "":
        running_time_list_random, running_time_list = get_running_time(
            LIVESTR_TIMETABLE_FILE)
        if (len(running_time_list) == 0):
            print("no time interval matched current time")
            return

        current_time = time_process.get_current_time()
        # If current time is earlier than the interval
        while (not time_process.compare_t2t(current_time,
                                            running_time_list[0])):
            sleep(1)
            current_time = time_process.get_current_time()

        # If current time is in the interval already, then only excuse connections
        # which are later than the current time
        while True:
            # Get current time
            current_time = time_process.get_current_time()
            #print("current_time:" + current_time)
            # If the current time is out of interval, break
            if (time_process.compare_t2t(current_time, running_time_list[-1])):
                break
            # If current time is in the running_time_list, run
            if current_time in running_time_list and current_time != tmp:
                tmp = current_time
                count += 1
                http_actions.live_stream(livestr_site_list, tapas_dir)
            # If not, sleep one sec and check again
            else:
                sleep(1)
        print(count)
    else:
        for i in range(0, NUM_CONN):
            http_actions.live_stream(livestr_site_list, tapas_dir)
Exemplo n.º 5
0
def imap():
    if READMAIL_TIMETABLE_FILE != "":
        running_time_list_random, running_time_list_ordered = get_running_time(
            READMAIL_TIMETABLE_FILE)
        if running_time_list_random == None:
            print("no time interval matched current time")
            return

        #for running_time in running_time_list_random:
        #    print(running_time)

        num_cxn = len(running_time_list_random)
        num_readmail_mean = rand_funcs.float_to_int(num_cxn * 0.5)
        num_reply_mean = rand_funcs.float_to_int(num_readmail_mean * 0.3)

        print("num_conn, num_readmail_mean, num_reply_mean", num_cxn,
              num_readmail_mean, num_reply_mean)

        for running_time in running_time_list_random:
            # Get the current time
            current_time = time_process.get_current_time()
            while (not time_process.compare_t2t(current_time, running_time)):
                sleep(1)
                current_time = time_process.get_current_time()

            one_read_email(num_readmail_mean, num_reply_mean)
    else:
        num_readmail_mean = rand_funcs.float_to_int(NUM_CONN * 0.5)
        num_reply_mean = rand_funcs.float_to_int(num_readmail_mean * 0.3)

        print("num_conn, num_readmail_mean, num_reply_mean", NUM_CONN,
              num_readmail_mean, num_reply_mean)
        for i in range(0, NUM_CONN):
            now = time.time()
            one_read_email(num_readmail_mean, num_reply_mean)
            then = time.time()
            print(then - now)
Exemplo n.º 6
0
def get_running_time(timetable):
    # List of running time
    running_time_list = []
    # Get the current time
    current_time = time_process.get_current_time()
    print(current_time)
    # Get the corresponding time_interval and numsession from the mail_timetable file
    interval_numsession_dict = timetable_process.get_time_interval(
        current_time, timetable)
    if interval_numsession_dict == None:
        return
    else:
        running_time_list_random = time_process.generate_random_running_time(
            interval_numsession_dict)
        running_time_list_ordered = time_process.generate_ordered_running_time(
            interval_numsession_dict)

    return running_time_list_random, running_time_list_ordered
Exemplo n.º 7
0
def check_run_time(run_time):
    # Get the current time
    current_time = time_process.get_current_time()
    while (not time_process.compare_t2t(current_time, run_time)):
        sleep(1)
        current_time = time_process.get_current_time()