可用于宝塔的脚本库,自用来刷一些简单的请求
import requests
import random
def generate_random_ip():
return '.'.join(str(random.randint(0, 255)) for _ in range(4))
# 要请求的URL列表
urls = [
'http://example.com',
'http://example.org',
'http://example.net'
]
# 伪造请求头的函数
def create_headers():
random_ip = generate_random_ip()
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
'X-Forwarded-For': random_ip, # 随机生成的IP地址
'X-Real-IP': random_ip # 随机生成的IP地址
}
return headers
# 发送请求并输出结果的函数
def send_requests(urls):
for url in urls:
headers = create_headers()
response = requests.get(url, headers=headers)
print(f'URL: {url}')
print(f'Random IP: {headers["X-Forwarded-For"]}')
print(f'Status Code: {response.status_code}')
print(f'Content: {response.text[:100]}...') # 只输出前100个字符
print('--------------------------------')
# 执行请求
send_requests(urls)