OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to Measure Latency (ms) of ss://, vless://, and vmess:// Connections on Specific Iranian ISPs (MCI, IRANCELL, SHATEL, RIGHTEL) Using Python?

  • Thread starter Thread starter morpheus adam
  • Start date Start date
M

morpheus adam

Guest
I want to measure the latency (ms) of my ss://, vless://, and vmess:// connections on specific Iranian ISPs such as MCI, IRANCELL, SHATEL, and RIGHTEL using Python. I am currently using a basic ping method, but I am not sure how to ensure that the tests are performed on servers connected to these specific ISPs

Is there a better approach ؟

Code:
`import subprocess

 def test_delay(connection):
    try:
   
        parts = connection.split('@')
        if len(parts) < 2:
            print(f"Invalid connection format: {connection}")
            return False
        
        server_info = parts[1].split('#')[0]
        if ':' in server_info:
            server_address, server_port = server_info.split(':')
        else:
            server_address = server_info
            server_port = None
        
         if server_address.startswith('[') and server_address.endswith(']'):
            server_address = server_address[1:-1]
        
         ping_command = ["ping", "-c", "1", server_address]
        response = subprocess.run(ping_command, capture_output=True)
        
        if response.returncode == 0:
            print(f"Delay for {server_address}: OK")
            return True
        else:
            print(f"Failed to reach the server: {server_address}")
            return False
    except Exception as e:
        print(f"An error occurred: {e}")
        return False

 try:
    with open("sub1.txt", "r") as file:
        connections = file.readlines()
    
    print("Testing delay for ss:// connections in sub1.txt...")
    with open("mci.txt", "w") as output_file:
        for connection in connections:
            connection = connection.strip()
            if test_delay(connection):
                output_file.write(f"{connection}\n")
except Exception as e:
    print(f"Failed to read connections from file: {e}")`
<p>I want to measure the latency (ms) of my ss://, vless://, and vmess:// connections on specific Iranian ISPs such as MCI, IRANCELL, SHATEL, and RIGHTEL using Python. I am currently using a basic ping method, but I am not sure how to ensure that the tests are performed on servers connected to these specific ISPs</p>
<p>Is there a better approach ؟</p>
<pre><code>`import subprocess

def test_delay(connection):
try:

parts = connection.split('@')
if len(parts) < 2:
print(f"Invalid connection format: {connection}")
return False

server_info = parts[1].split('#')[0]
if ':' in server_info:
server_address, server_port = server_info.split(':')
else:
server_address = server_info
server_port = None

if server_address.startswith('[') and server_address.endswith(']'):
server_address = server_address[1:-1]

ping_command = ["ping", "-c", "1", server_address]
response = subprocess.run(ping_command, capture_output=True)

if response.returncode == 0:
print(f"Delay for {server_address}: OK")
return True
else:
print(f"Failed to reach the server: {server_address}")
return False
except Exception as e:
print(f"An error occurred: {e}")
return False

try:
with open("sub1.txt", "r") as file:
connections = file.readlines()

print("Testing delay for ss:// connections in sub1.txt...")
with open("mci.txt", "w") as output_file:
for connection in connections:
connection = connection.strip()
if test_delay(connection):
output_file.write(f"{connection}\n")
except Exception as e:
print(f"Failed to read connections from file: {e}")`
</code></pre>
 

Latest posts

Top