随笔 - 241  文章 - 1  评论 - 58  阅读 - 85万 

内容

复制代码
global
        log 127.0.0.1 local2
        daemon
        maxconn 256
        log 127.0.0.1 local2 info
defaults
        log global
        mode http
        timeout connect 5000ms
        timeout client 50000ms
        timeout server 50000ms
        option  dontlognull

listen stats :8888
        stats enable
        stats uri       /admin
        stats auth      admin:1234

frontend 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 www

backend www.oldboy1.org
        server 10.10.0.10 10.10.0.10 weight 9999 maxconn 33333333333
        server 10.10.10.1 10.10.10.1 weight 22 maxconn 2000
        server 2.2.2.4 2.2.2.4 weight 20 maxconn 3000
backend www.oldboy2.org
        server 3.3.3.3 3.3.3.3 weight 20 maxconn 3000
backend www.oldboy20.org
        server 10.10.0.10 10.10.0.10 weight 9999 maxconn 33333333333
复制代码

 

 

复制代码
 1 arg = {'backend': 'www.oldboy.org','record':{'server':'10.10.0.10 10.10.0.10',"weight":"9999", "maxconn": "33333333333"}}
 2 count=0
 3 while True:
 4     choice=eval(input("请输入一个字典{}"))
 5     with open( "haproxy.conf",'r') as a,open("b.txt",'w') as b:
 6         for line in a:
 7             count+=1
 8             if count==26:
 9              b.write (str(choice["backend"]))
10              b.write('\n')
11              b.write(str(choice["record"]).strip('{}'))
12             else:b.write(line)
复制代码

 

删除:

复制代码
import sys, time
count=0
l=[]
while True:
    with open( "haproxy.conf",'r') as a:
            for i in a:
                count+=1
                print(i,count)
            else:
                count=0
                print(count)
    choice=input("请输入要删除的行---->:").strip()
    for i in choice:
        if i.isdigit():
            l.append(int(i))
    with open( "haproxy.conf",'r') as a,open("b.txt",'w') as b:
        for line in  a:
            count+=1
            if count in l:
                continue
            else:
                b.write(line)
    for i in l:
        sys.stdout.write("\r ##########正在删除第%s行#########" % i)
        sys.stdout.flush()
        time.sleep(1)
    exit(print('\n 再见!'))
复制代码

 

复制代码
arg = {'backend': 'www.oldboy.org','record':{'server':'10.10.0.10 10.10.0.10',"weight":"9999", "maxconn": "33333333333"}}

while True:
    choice = eval(input("请输入一个字典{}:").strip())
    with open( "haproxy.conf",'r') as a,open("b.txt",'w') as b:
      for line in a:
            if line.startswith("backend") and choice["backend"] in line:
                continue
            if choice["record"]['server'] in line:
                continue
            else:
                b.write(line)
复制代码

 删2:

  

复制代码
count=0
while True:
    with open( "haproxy.conf",'r') as a:
        for i in a:
            count+=1
            print(i,count)
        else:
            count=0
            print(count)
    choice=int(input("请输入删除的行:"))
    print(choice)
    with open( "haproxy.conf",'r') as a,open("b.txt",'w') as b:
        for line in  a:
            count+=1
            if count==choice:
                continue
            else:
                b.write(line)
复制代码

 

 

 

 

 

 改

复制代码
count=0
while True:
    choice=eval(input("请输入一个字典{}")) # choice=eval(input("请输入一个字典{}"))
    with open( "haproxy.conf",'r') as a,open("b.txt",'w') as b:
        for line in a:
            count+=1
            if count==28:
                b.write(str(choice["backend"]).strip())
                continue
            if count==29:
                b.write("\n")
                continue
            if count==30:
                for k,v in dict(choice['record']).items():
                  b.write('    ') 
                  b.write(k)
                  b.write("   ")
                  b.write(v)
                continue
            if count==31:
                b.write("\n")
                continue
            else:
                b.write(line)
复制代码

 

 

 

 

复制代码
 1 while True:
 2     l=[]
 3     m=input("请输入您要查询的内容: ").strip()
 4     flag=False
 5     with open('haproxy.conf','r') as  ha1:
 6         for line in ha1:
 7             if line.startswith("backend") and m in line:  #第一步 定位到 backend行
 8                 flag=True
 9                 continue
10             if flag==True:                                #第二步 设置标志开关
11                 l.append(line)
12             if line.startswith("backend") and flag:      #第三步 跳出循环
13                 break
14         for i in  l:
15             print(i)
复制代码

 用户登录三次锁定:

复制代码
count=0
while True:
    user=input("请输入您的用户名: ").strip()
    with open("lock_account",'r') as a:
        for i in  a:
           if user==i.strip():
                exit("您的账户已被锁定")
    password = input("请输入密码: ").strip()
    count+=1
    flag = False
    with open("account.txt", 'r') as b:
        for line in b:
           use,psw = line.strip().split()
           if user== use and password==psw:
               count=0
               print("---------欢迎登录-------- ")

    if count==3 and flag==False:
        with open("lock_account", 'a') as a:
            a.write(user)
            a.write('\n')
            exit("输入次数超过3次,你的账户被锁定了")
复制代码

 定义函数精简版

复制代码
count=0
def open_lockaccount(user):
    with open("lock_account",'r') as a:
        for i in  a:
           if user==i.strip():
                exit("您的账户已被锁定")
def open_account(user,passwd):
    with open("account.txt", 'r') as b:
        for line in b:
           use,psw = line.strip().split()
           if user== use and password==psw:
               count = 0
               print("---------欢迎登录-------- ")
def write_account(user):
    with open("lock_account", 'a') as a:
        a.write(user)
        a.write('\n')
        exit("输入次数超过3次,你的账户被锁定了")
while True:
    user=input("请输入您的用户名: ").strip()
    open_lockaccount(user)
    password = input("请输入密码: ").strip()
    count+=1
    flag = False
    open_account(user, password)
    if count == 3 and flag == False:
        write_account(user)
复制代码

 

posted on   Martin8866  阅读(330)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示