Python脚本:修改Bind域名解析文件(3)

def list_dns_record(conf_file, key_words):
    print "\033[36;1m" + "-" * 80 + "\033[0m"
    print "\033[33;1mThe config file " + conf_file + " records:\033[0m"
    print "\033[36;1m" + "-"*80 + "\033[0m"
    conf = open(conf_file)
    line_num = 1
    line_num_list = []
    for line in conf:
        if line.find(key_words) > 0:
            print "\033[31;1m" + str(line_num) + ")\033[0m\t" + line,
            line_num_list.append(line_num)
        line_num += 1
    print "\033[33;1mThe End of " +  conf_file + "\033[0m\n"
    return line_num_list

def menu_printer(menu_title, menu_list = []):
    print "\033[36;1m" + "-"*80 + "\033[0m"
    print "\033[32;1m" + menu_title + "\033[0m"
    print "\033[33;1mMenu:\033[0m"
    num = 1
    for item in menu_list:
        print "\033[31;1m" + str(num)  + ".\033[36;1m" + item + "\033[0m"
        num += 1
    print "\033[36;1m" + "-"*80 + "\033[0m"

def show_all_dns_record():
    while True:
        menu_item = ['Print forward resolution record','Print reverse parsing record','Print All','Exit']
        menu_printer("Print DNS Record", menu_item)
        select_menu_num = check_menu_select(menu_item)
        if select_menu_num == "1":
            list_dns_record(forward_resolution_conf,'IN A')
        elif select_menu_num == "2":
            list_dns_record(reverse_parsing_conf,'IN PTR')
        elif select_menu_num == "3":
            list_dns_record(forward_resolution_conf,'IN A')
            list_dns_record(reverse_parsing_conf,'IN PTR')
        else:
            break
    show_main_menu()

def check_menu_select(menu_item = []):
    select_menu_num = 0
    while True:
        select_menu_num = raw_input("\033[32;1mPlease input the number of Menu:\033[0m").strip()
        if select_menu_num.isdigit()  == False:
            print "\033[31;1mYour input is not a number, please try again!\033[0m"
            continue
        elif int(select_menu_num) <= 0 or int(select_menu_num) > len(menu_item):
            print "\033[31;1mYour input should be between 1 to " + str(len(menu_item)) + ", please try agiain!\033[0m"
            continue
        else:
            break
    return select_menu_num

def deleted_record_num_exist(conf_file, key_words):
    while True:
        line_num_list = list_dns_record(conf_file, key_words)
        delete_record_num = raw_input("\033[32;1mPlease input the record line number which you want to delete(input 'exit' to quit):\033[0m").strip()
        if delete_record_num == 'exit':
            break
        is_have_num_in_list = False
        for num in line_num_list:
            if int(delete_record_num) == num:
                is_have_num_in_list = True
        if is_have_num_in_list == True:
            delete_certain_record(conf_file, int(delete_record_num) -1)
            list_dns_record(conf_file, key_words)
            print "\033[33;1m" + "*"*80 + "\033[0m"
            print "\033[31;1m**The record you specified is deleted, Please check out the Record list above!**\033[0m"
            print "\033[33;1m" + "*"*80 + "\033[0m"
            break
        else:
            print "\033[33;1m" + "*"*80 + "\033[0m"
            print "\033[31;1mThe record line number you input is not exist, Please check the list below!\033[0m"
            print "\033[33;1m" + "*"*80 + "\033[0m"
            continue

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/71cb709dd098af12cbdd1431de67ca4c.html