首页 > 代码库 > 对文件的增删改查 以及 ---三次登陆
对文件的增删改查 以及 ---三次登陆
文件
global log 127.0.0.1 local2 daemon maxconn 256 log 127.0.0.1 local2 infodefaults log global mode http timeout connect 5000ms timeout client 50000ms timeout server 50000ms option dontlognulllisten stats :8888 stats enable stats uri /admin stats auth admin:1234frontend oldboy.org bind 0.0.0.0:80 option httplog option httpclose option forwardfor log global acl www hdr_reg(host) -i www.oldboy.org use_backend www.oldboy.org if wwwbackend wwww.baidu.com server 1.1 weight 666666 maxconn 2.2.2.2.2 server 5555555 weight 20 maxconn 3000 server 88 weight 88 maxconn 88 server 6.6.6 5.5.5 weight 11 maxconn 88.88 server 666.22 weight 9999 maxconn 8.8.8 server 7.7.7.7.7 1.1.1.1.1.1 weight 1.4.5.6.2 1 maxconn 4.4.1000000 server 11111 weight 11111 maxconn 11111 server 55.55 55.22 weight 20 maxconn 3000backend www.oldboy2.org server 3.3.3.3 3.3.3.3 weight 20 maxconn 3000backend www.oldboy20.org server 10.10.0.10 10.10.0.10 weight 9999 maxconn 33333333333
代码
import osdef search(old_Value): print(‘查看选中的内容‘) print(‘server %s weight %s maxconn %s‘ % (old_Value[‘record‘][‘server‘], old_Value[‘record‘][‘weight‘], old_Value[‘record‘][‘maxconn‘]))def change(f_write,New_Value1): print(‘修改成功‘) f_write.write(New_Value1)def delete(): print(‘成功删除‘)def upadd(f_write,New_Value1): print(‘添加成功‘) f_write.write(New_Value1)def upadd_del_change(old_Value,New_Value1): flag = False with open(‘haproxy.conf‘,‘r‘,encoding=‘utf-8‘) as f_read, open(‘haproxy_test.conf‘,‘w+‘,encoding=‘utf-8‘) as f_write: for i in f_read: if i.startswith(‘backend‘) and old_Value[‘backend‘] in i: flag = True if old_Value[‘record‘][‘server‘] in i and old_Value[‘record‘][‘weight‘] in i and old_Value[‘record‘][‘maxconn‘] in i and flag: flag = False num_input = int(input(‘请输入(1(添加) or 2(删除) or 3(修改)or 4(查看)):‘).strip()) if num_input == 1: upadd(f_write, New_Value1) if num_input == 2: delete() continue if num_input == 3: change(f_write, New_Value1) continue if num_input == 4: search(old_Value) f_write.write(i) os.rename(‘haproxy.conf‘,‘haproxy1.conf‘) os.rename(‘haproxy_test.conf‘,‘haproxy.conf‘) os.remove(‘haproxy1.conf‘)if __name__ == ‘__main__‘: while True: #{‘backend‘:‘wwww.baidu.com‘,‘record‘:{‘server‘:‘5555555‘,‘weight‘:‘20‘,‘maxconn‘:‘3000‘}} old_Value = http://www.mamicode.com/eval(input(‘Please enter the old value:‘)) New_Value = eval(input(‘Please enter a new value:‘)) New_Value1 = (‘\t\tserver %s weight %s maxconn %s\n‘ % (New_Value[‘record‘][‘server‘], New_Value[‘record‘][‘weight‘], New_Value[‘record‘][‘maxconn‘])) upadd_del_change(old_Value, New_Value1)
三次登陆
#!/usr/bin/python# -*- coding: UTF-8 -*-#名单文件:username#黑名单文件:lock‘‘‘1.先打开文件,2.创建杂货,3.对文件进行操作4.进行循环5.输入用户名进行判断, (1).用户名是否存在 (1).存在的话就退出本次循环 (2)不在的话, (1)进行验证, (1)验证成功的。 (2)不成功 (1)不成功的在进行验证, (1)在定义的字典中,是否存在了,存在的次数不超过3次就进行自加 (2)不在定义的字典中,将用户名添加进去, (2)用户不存在的 (1)提示用户不存在,返回‘‘‘f_read = open(‘username‘)f_write = open(‘lock‘,‘a+‘,encoding=‘utf-8‘)flag = Truedic_list = {}count = 0while flag and count < 3: user = input(‘输入用户名:‘) pwd = input(‘输入密码:‘) f_read.seek(0) f_write.seek(0) for i in f_write: if user == i: print(‘用户名已经锁定了!找管理人员给你解锁.....‘) break else: for i in f_read: username,pwds = i.strip().split(‘ ‘) if username ==user : if pwds == pwd : print(‘login 成功!‘) flag = False break else: if username in dic_list: dic_list[username] += 1 else: dic_list[username] = 1 print(‘你输入的用户或密码错误‘) count = 1 else: if count == 0: print("你输入的用户不存在.....") for i in dic_list: if dic_list[i] == 3: count = 3 breakif flag: print(‘该用户密码输入三次错误,已被锁定,请联系管理员‘) f_write.write(user)f_read.close()f_write.close()
对文件的增删改查 以及 ---三次登陆
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。