-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_headers.py
More file actions
213 lines (170 loc) · 8.58 KB
/
generate_headers.py
File metadata and controls
213 lines (170 loc) · 8.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env python3
"""
Random Headers Generator
Generates 1000 realistic browser headers for proxy validation
"""
import json
import os
import random
from datetime import datetime
def generate_random_headers():
"""Generate 1000 random realistic browser headers"""
# Common user agents from different browsers and platforms
user_agents = [
# Chrome Windows
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
"Mozilla/5.0 (Windows NT 11.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
# Chrome macOS
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
# Firefox Windows
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/118.0",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/117.0",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0",
# Firefox macOS
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/118.0",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/117.0",
# Safari macOS
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Safari/605.1.15",
# Edge Windows
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.76",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.60",
# Chrome Linux
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36",
# Firefox Linux
"Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/118.0",
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/118.0",
# Mobile browsers
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1",
"Mozilla/5.0 (Linux; Android 13; SM-G991B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Mobile Safari/537.36",
"Mozilla/5.0 (iPad; CPU OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1",
]
# Common accept headers
accept_headers = [
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"application/json,text/plain,*/*",
"*/*",
]
# Accept-Language options
accept_languages = [
"en-US,en;q=0.9",
"en-GB,en;q=0.9",
"en-US,en;q=0.8,es;q=0.6",
"en-US,en;q=0.9,fr;q=0.8",
"en-US,en;q=0.9,de;q=0.8",
"en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7",
"fr-FR,fr;q=0.9,en;q=0.8",
"de-DE,de;q=0.9,en;q=0.8",
"es-ES,es;q=0.9,en;q=0.8",
"zh-CN,zh;q=0.9,en;q=0.8",
]
# Accept-Encoding options
accept_encodings = [
"gzip, deflate, br",
"gzip, deflate",
"gzip",
"br",
]
# Connection options
connections = ["keep-alive", "close"]
# DNT options
dnt_options = ["1", "0"]
# Upgrade-Insecure-Requests
upgrade_insecure = ["1", "0"]
# Sec-Fetch options
sec_fetch_dest = ["document", "empty", "image", "script", "style"]
sec_fetch_mode = ["navigate", "cors", "no-cors", "same-origin"]
sec_fetch_site = ["none", "same-origin", "same-site", "cross-site"]
headers_list = []
for i in range(1000):
# Create a random header set
headers = {
"User-Agent": random.choice(user_agents),
"Accept": random.choice(accept_headers),
"Accept-Language": random.choice(accept_languages),
"Accept-Encoding": random.choice(accept_encodings),
"Connection": random.choice(connections),
}
# Randomly add optional headers
if random.random() > 0.3: # 70% chance
headers["DNT"] = random.choice(dnt_options)
if random.random() > 0.4: # 60% chance
headers["Upgrade-Insecure-Requests"] = random.choice(
upgrade_insecure)
if random.random() > 0.5: # 50% chance
headers["Sec-Fetch-Dest"] = random.choice(sec_fetch_dest)
headers["Sec-Fetch-Mode"] = random.choice(sec_fetch_mode)
headers["Sec-Fetch-Site"] = random.choice(sec_fetch_site)
if random.random() > 0.7: # 30% chance
headers["Cache-Control"] = random.choice(["no-cache", "max-age=0"])
if random.random() > 0.8: # 20% chance
headers["Pragma"] = "no-cache"
if random.random() > 0.6: # 40% chance
headers["Sec-Ch-Ua"] = '"Google Chrome";v="118", "Chromium";v="118", "Not=A?Brand";v="99"'
headers["Sec-Ch-Ua-Mobile"] = "?0"
headers["Sec-Ch-Ua-Platform"] = random.choice(
['"Windows"', '"macOS"', '"Linux"'])
headers_list.append(headers)
return headers_list
def save_headers_to_files(headers_list, data_dir="data"):
"""Save headers to both JSON and TXT formats"""
# Create data directory if it doesn't exist
os.makedirs(data_dir, exist_ok=True)
# Save as JSON for programmatic use
json_file = os.path.join(data_dir, "headers.json")
with open(json_file, 'w', encoding='utf-8') as f:
json.dump({
"generated_at": datetime.now().isoformat(),
"total_headers": len(headers_list),
"headers": headers_list
}, f, indent=2, ensure_ascii=False)
# Save as TXT for human reading
txt_file = os.path.join(data_dir, "headers.txt")
with open(txt_file, 'w', encoding='utf-8') as f:
f.write(f"# Random Headers Database\n")
f.write(
f"# Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
f.write(f"# Total headers: {len(headers_list)}\n")
f.write(f"# Purpose: Randomize HTTP headers for proxy validation\n\n")
for i, headers in enumerate(headers_list, 1):
f.write(f"# Header Set {i}\n")
for key, value in headers.items():
f.write(f"{key}: {value}\n")
f.write("\n")
print(f"✅ Generated {len(headers_list)} random headers")
print(f"📄 Saved to: {json_file}")
print(f"📄 Saved to: {txt_file}")
return json_file, txt_file
def load_random_header(json_file="data/headers.json"):
"""Helper function to load a random header from the generated file"""
try:
with open(json_file, 'r', encoding='utf-8') as f:
data = json.load(f)
return random.choice(data['headers'])
except Exception as e:
print(f"Error loading headers: {e}")
# Fallback header
return {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.9",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive"
}
if __name__ == "__main__":
print("🔄 Generating 1000 random headers...")
headers = generate_random_headers()
save_headers_to_files(headers)
print("\n🧪 Testing random header loading...")
sample_header = load_random_header()
print("Sample header:")
for key, value in sample_header.items():
print(f" {key}: {value}")
print("\n✅ Headers generation completed!")