예제 #1
0
def start_monitor(st_list_filepath,user_name,user_pwd):
    st_list = student_model.get_st_list(st_list_filepath)
    crawler = PAT_crawler(user_name, user_pwd, "")

    try:
        fp = open("media/monitor_result.txt","a+")
    except IOError:
        print "Error open result.txts error!"

    print "===start testing,see the result in console or result.txt ======================\n"
    ip2ids = {}
    while True:
        try:
            for i in range(len(st_list)):
                current_ip = crawler.get_ip_by_name(st_list[i].id)
                if current_ip == "":
                    #never logined
                    continue

                #login
                if ip2ids.has_key(current_ip) == False:
                    ip2ids[current_ip] = []
                if ip2ids[current_ip].count(st_list[i])==0:
                    ip2ids[current_ip].append(st_list[i])
                    if current_ip!="127.0.0.1" and len(ip2ids[current_ip]) > 1:
                        content = "\n%s:---------one ip with multiple id ---------\n" % time.strftime('%Y-%m-%d %H:%M',time.localtime(time.time()))
                        content = content + "ip:%s\n" % current_ip
                        content = content + "logined students:\n"+'\n'.join(str(tst) for tst in ip2ids[current_ip])
                        print content.decode('utf-8').encode(EncodeType)
                        fp.write(content)
                        fp.flush()

                llen = len(st_list[i].ips)
                if llen == 0:
                    st_list[i].ips.append(current_ip)
                else:
                    if st_list[i].last_ip != current_ip:
                        #different login ip detected
                        #print last ip and current ip
                        #print current ip has logined whos
                        #print this id has logined which ips
                        if st_list[i].ips.count(current_ip)==0:
                            st_list[i].ips.append( current_ip)
                        content = "\n%s:---------one id with multiple ip ---------\n" % time.strftime('%Y-%m-%d %H:%M',time.localtime(time.time()))
                        content = content + str(st_list[i])+":\n"
                        content = content + "logined ip:\n"+'\n'.join(st_list[i].ips)
                        content = content + '\ncurrent_ip:'+current_ip
                        print content.decode('utf-8').encode(EncodeType)
                        fp.write(content)
                        fp.flush()
                st_list[i].last_ip = current_ip
        except KeyboardInterrupt:
            print "exting..."
            fp.close()
            print "bye"
            raw_input("Press Enter to continue......")
            sys.exit()
예제 #2
0
파일: norm2rand.py 프로젝트: etaf/asist4cpp
def main(input_filename, save_dir):
    st_list = get_st_list(input_filename)
    single_set = {}
    rand_str = "abcdefghijkmnpqrstwxy23456789"
    for i in range(len(st_list)):
        st_list[i].rand_id = get_rand_id(single_set,rand_str)
        st_list[i].rand_pwd = get_rand_pwd(rand_str)

    write_xls(st_list, save_dir)
    write_txt(st_list, save_dir)
예제 #3
0
파일: monitor.py 프로젝트: etaf/asist4cpp
def main():
    # for sig in (SIGABRT, SIGILL, SIGINT, SIGSEGV, SIGTERM):
    # for sig in ( SIGINT, SIGTERM):
    # signal(sig, try_exit)
    signal(SIGTERM, try_exit)
    args = args_process()
    st_list = student_model.get_st_list("./media/norm2rand.txt")
    crawler = PAT_crawler(args.username, args.password, "")
    try:
        fp = open("./media/monitor_result.txt", "a+")
    except IOError:
        monitor_logger.error("Error open result.txts error!")
        print "Error open result.txts error!"

    print "===start testing,see the result in console or result.txt ======================\n"
    monitor_logger.info("start monitoring")
    ip2ids = {}
    try:
        while True:
            #            print "hello"
            # fp.write("hello~ now: "+time.strftime('%Y-%m-%d %H:%M',time.localtime(time.time()))+"<br>")
            # fp.flush()
            # time.sleep(1)
            # continue
            for i in range(len(st_list)):
                current_ip = crawler.get_ip_by_name(st_list[i].rand_id)
                if current_ip == "":
                    # never logined
                    continue
                # login
                if ip2ids.has_key(current_ip) == False:
                    ip2ids[current_ip] = []
                if ip2ids[current_ip].count(st_list[i]) == 0:
                    ip2ids[current_ip].append(st_list[i])
                    # if current_ip!="127.0.0.1" and len(ip2ids[current_ip]) > 1:
                    if len(ip2ids[current_ip]) > 1:
                        content = (
                            "<div class='panel panel-warning'> <div class='panel-heading'> <h4 class='panel-title'>"
                        )
                        content = content + "%s: one ip with multiple students" % time.strftime(
                            "%Y-%m-%d %H:%M", time.localtime(time.time())
                        )
                        content = content + " </h4> </div> <div class='panel-body'>"
                        content = content + "ip: %s<br>" % current_ip
                        content = content + "<br>".join(str(tst) for tst in ip2ids[current_ip])
                        content = content + " </div> </div> </div>"
                        fp.write(content)
                        fp.flush()
                llen = len(st_list[i].ips)
                if llen == 0:
                    st_list[i].ips.append(current_ip)
                else:
                    if st_list[i].last_ip != current_ip:
                        # different login ip detected
                        # print last ip and current ip
                        # print current ip has logined whos
                        # print this id has logined which ips
                        if st_list[i].ips.count(current_ip) == 0:
                            st_list[i].ips.append(current_ip)

                        content = (
                            "<div class='panel panel-danger'> <div class='panel-heading'> <h4 class='panel-title'>"
                        )
                        content = content + "%s: one stduent with multiple ip" % time.strftime(
                            "%Y-%m-%d %H:%M", time.localtime(time.time())
                        )
                        content = content + " </h4> </div> <div class='panel-body'>"
                        content = content + str(st_list[i]) + ":<br>"
                        content = content + "previous logined ip:<br>" + "<br>".join(st_list[i].ips)
                        content = content + "<br>current logined_ip:" + current_ip
                        content = content + " </div> </div> </div>"
                        fp.write(content)
                        fp.flush()
                st_list[i].last_ip = current_ip
            time.sleep(1)
    except Exception as e:
        print e
        monitor_logger.error(str(e))
    finally:
        fp.close()
        monitor_logger.info("stop monitoring")
        print "Good Bye!"
예제 #4
0
파일: monitor.py 프로젝트: etaf/CppTA
def main():

    EncodeType = sys.getfilesystemencoding()
    args = args_process()
    st_list = student_model.get_st_list(args.student_list_file)

    tmp = get_name_pwd_from_console()
    crawler = PAT_crawler(tmp[0], tmp[1])

    while crawler.logined() == False:
        print "login error! try your account and password again!\n"
        tmp = get_name_pwd_from_console()
        crawler.login(tmp[0], tmp[1])
    try:
        fp = open("result.txt", "a+")
    except IOError:
        print "Error open result.txts error!"
        raw_input("Press Enter to continue......")
        sys.exit()
    print "===start testing,see the result in console or result.txt ======================\n"
    ip2ids = {}
    while True:
        try:
            for i in range(len(st_list)):
                current_ip = crawler.get_ip_by_name(st_list[i].id)
                if current_ip == "":
                    #never logined
                    continue

                #login
                if ip2ids.has_key(current_ip) == False:
                    ip2ids[current_ip] = []
                if ip2ids[current_ip].count(st_list[i]) == 0:
                    ip2ids[current_ip].append(st_list[i])
                    if current_ip != "127.0.0.1" and len(
                            ip2ids[current_ip]) > 1:
                        content = "\n%s:---------one ip with multiple id ---------\n" % time.strftime(
                            '%Y-%m-%d %H:%M', time.localtime(time.time()))
                        content = content + "ip:%s\n" % current_ip
                        content = content + "logined students:\n" + '\n'.join(
                            str(tst) for tst in ip2ids[current_ip])
                        print content.decode('utf-8').encode(EncodeType)
                        fp.write(content)
                        fp.flush()

                llen = len(st_list[i].ips)
                if llen == 0:
                    st_list[i].ips.append(current_ip)
                else:
                    if st_list[i].last_ip != current_ip:
                        #different login ip detected
                        #print last ip and current ip
                        #print current ip has logined whos
                        #print this id has logined which ips
                        if st_list[i].ips.count(current_ip) == 0:
                            st_list[i].ips.append(current_ip)
                        content = "\n%s:---------one id with multiple ip ---------\n" % time.strftime(
                            '%Y-%m-%d %H:%M', time.localtime(time.time()))
                        content = content + str(st_list[i]) + ":\n"
                        content = content + "logined ip:\n" + '\n'.join(
                            st_list[i].ips)
                        content = content + '\ncurrent_ip:' + current_ip
                        print content.decode('utf-8').encode(EncodeType)
                        fp.write(content)
                        fp.flush()
                st_list[i].last_ip = current_ip
        except KeyboardInterrupt:
            print "exting..."
            fp.close()
            print "bye"
            raw_input("Press Enter to continue......")
            sys.exit()
예제 #5
0
파일: norm2rand.py 프로젝트: etaf/CppTA

def test_self(st_list):
    single_set = {}
    flag = True
    for st in st_list:
        if single_set.has_key(st.rand_id):
            print "Error : rand id not unique!"
            flag = False
            break
        else:
            single_set[st.rand_id] = 1
    if flag:
        print "test self : OK!"


if __name__ == "__main__":

    st_list = get_st_list("student_list.txt")

    single_set = {}

    for i in range(len(st_list)):
        st_list[i].rand_id = get_rand_id(single_set)
        st_list[i].rand_pwd = get_rand_pwd()

    write_xls(st_list)
    write_txt(st_list)

    test_self(st_list)
예제 #6
0
파일: norm2rand.py 프로젝트: etaf/CppTA

def test_self(st_list):
    single_set = {}
    flag = True
    for st in st_list:
        if single_set.has_key(st.rand_id):
            print "Error : rand id not unique!"
            flag = False
            break
        else:
            single_set[st.rand_id] = 1
    if flag:
        print "test self : OK!"


if __name__ == '__main__':

    st_list = get_st_list("student_list.txt")

    single_set = {}

    for i in range(len(st_list)):
        st_list[i].rand_id = get_rand_id(single_set)
        st_list[i].rand_pwd = get_rand_pwd()

    write_xls(st_list)
    write_txt(st_list)

    test_self(st_list)