Skip to content

Commit

Permalink
Update iptest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Surfboardv2ray authored Nov 8, 2024
1 parent a6e5952 commit ca4e4d8
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions IPTest/iptest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ def rename_vmess_address(proxy, new_address):
base64_str += '=' * (4 - missing_padding)
try:
decoded_str = base64.b64decode(base64_str).decode('utf-8')
print("Decoded VMess proxy JSON:", decoded_str) # Debugging
proxy_json = json.loads(decoded_str)
proxy_json['add'] = new_address
proxy_json['ps'] = new_address # Set remarks to new address
proxy_counter += 1
encoded_str = base64.b64encode(json.dumps(proxy_json).encode('utf-8')).decode('utf-8')
renamed_proxy = 'vmess://' + encoded_str
print("Renamed VMess proxy:", renamed_proxy) # Debugging
return renamed_proxy
except Exception as e:
print("Error processing VMess proxy: ", e)
Expand All @@ -37,7 +35,6 @@ def rename_vless_address(proxy, new_address):
remarks = new_address # Set remarks to new address
renamed_proxy = userinfo + '@' + hostinfo + '#' + remarks
proxy_counter += 1
print("Renamed VLess proxy:", renamed_proxy) # Debugging
return renamed_proxy
except Exception as e:
print("Error processing VLess proxy: ", e)
Expand All @@ -55,33 +52,33 @@ def rename_trojan_address(proxy, new_address):
remarks = new_address # Set remarks to new address
renamed_proxy = userinfo + '@' + hostinfo + '#' + remarks
proxy_counter += 1
print("Renamed Trojan proxy:", renamed_proxy) # Debugging
return renamed_proxy
except Exception as e:
print("Error processing Trojan proxy: ", e)
return None

def process_proxies(input_file, ips_file, output_file):
# Read the single proxy configuration
# Read all proxy configurations from config.txt
with open(input_file, 'r') as f:
proxy = f.readline().strip()
proxies = [line.strip() for line in f.readlines() if line.strip()]

# Read the list of IP addresses, skipping lines that start with "//"
with open(ips_file, 'r') as ip_f:
ips = [line.strip() for line in ip_f.readlines() if not line.strip().startswith("//")]

# Process each IP address and create a new configuration
# Process each configuration with each IP address
with open(output_file, 'w') as out_f:
for i, ip in enumerate(ips):
if proxy.startswith('vmess://'):
renamed_proxy = rename_vmess_address(proxy, ip)
elif proxy.startswith('vless://'):
renamed_proxy = rename_vless_address(proxy, ip)
elif proxy.startswith('trojan://'):
renamed_proxy = rename_trojan_address(proxy, ip)
for proxy in proxies:
for ip in ips:
if proxy.startswith('vmess://'):
renamed_proxy = rename_vmess_address(proxy, ip)
elif proxy.startswith('vless://'):
renamed_proxy = rename_vless_address(proxy, ip)
elif proxy.startswith('trojan://'):
renamed_proxy = rename_trojan_address(proxy, ip)

if renamed_proxy is not None:
out_f.write(renamed_proxy + '\n')
if renamed_proxy is not None:
out_f.write(renamed_proxy + '\n')

# Example usage
input_file = 'IPTest/config.txt'
Expand Down

0 comments on commit ca4e4d8

Please sign in to comment.