内容
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)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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代理技术深度解析与实战指南