-
Notifications
You must be signed in to change notification settings - Fork 18
/
warp-on-warp-generator.py
108 lines (88 loc) · 3.72 KB
/
warp-on-warp-generator.py
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
import json
import os
import random
import string
import requests
# Define colors for better output formatting
GREEN = "\033[92m"
RED = "\033[91m"
YELLOW = "\033[93m"
RESET = "\033[0m"
def generate_random_string(length=8) -> str:
"""Generate a random string of specified length."""
return "".join(random.choices(string.ascii_letters + string.digits, k=length))
def load_json_template() -> dict:
"""Load the JSON template from the config-template.json file."""
try:
with open("config-template.json", "r") as file:
data = json.load(file)
return data
except IOError as e:
print(f"{RED}Error loading: config-template.json not found{RESET}\n{e}")
raise
def check_output_dir():
"""Create the output directory if it doesn't exist."""
output_dir = "output"
os.makedirs(output_dir, exist_ok=True)
def register_warp_account() -> dict:
"""Register a new Warp account."""
try:
response = requests.get("https://api.zeroteam.top/warp?format=sing-box").json()
return response
except requests.exceptions.RequestException as e:
print(f"{RED}Error registering account{RESET}\n{e}")
raise
def main():
try:
# Load the JSON template
json_file_to_save = load_json_template()
print(f"{GREEN}Config Template loaded.{RESET}")
# Register two Warp accounts
first_account = register_warp_account()
print(f"{GREEN}First account registered.{RESET}")
second_account = register_warp_account()
print(f"{GREEN}Second account registered.{RESET}")
# Update the JSON template with the registered accounts
json_file_to_save["outbounds"][2]["local_address"][1] = first_account[
"local_address"
][1]
json_file_to_save["outbounds"][2]["private_key"] = first_account["private_key"]
json_file_to_save["outbounds"][2]["reserved"] = first_account["reserved"]
json_file_to_save["outbounds"][3]["local_address"][1] = second_account[
"local_address"
][1]
json_file_to_save["outbounds"][3]["private_key"] = second_account["private_key"]
json_file_to_save["outbounds"][3]["reserved"] = second_account["reserved"]
# Ask for custom clean IP and port
use_custom_ip = (
input(
f"{YELLOW}[+] Do you want to use a custom clean IP? (y/N): {RESET}"
).lower()
== "y"
)
if use_custom_ip:
ip = input("Enter clean IP address: ").strip()
port = int(input("Enter clean port: ").strip())
json_file_to_save["outbounds"][2]["server"] = ip
json_file_to_save["outbounds"][2]["server_port"] = port
json_file_to_save["outbounds"][3]["server"] = ip
json_file_to_save["outbounds"][3]["server_port"] = port
else:
json_file_to_save["outbounds"][2]["server"] = "162.159.193.10"
json_file_to_save["outbounds"][2]["server_port"] = 2408
json_file_to_save["outbounds"][3]["server"] = "162.159.193.10"
json_file_to_save["outbounds"][3]["server_port"] = 2408
# Create the output directory
check_output_dir()
# Save the configuration to a file
config_name = f"{generate_random_string()}.json"
config_path = os.path.join("output", config_name)
with open(config_path, "w") as f:
json.dump(json_file_to_save, f, indent=2)
print(
f"\n{GREEN}Config was successfully created!{RESET}\n{GREEN}Generated config saved:\n {RESET}{config_path}\n"
)
except Exception as e:
print(f"{RED}[+] Couldn't make the config.\nThere was an error:{RESET}\n{e}")
if __name__ == "__main__":
main()