import socket
import socks
import time
def ping_minecraft_server(server_ip, server_port, proxy_list_file):
# Read the proxy list file
with open(proxy_list_file, 'r') as file:
proxies = file.readlines()
# Remove newline characters and empty lines
proxies = [proxy.strip() for proxy in proxies if proxy.strip()]
# Loop through the proxies and try pinging the server
for proxy in proxies:
proxy = proxy.split(':')
proxy_ip = proxy[0]
proxy_port = int(proxy[1])
print(f"Pinging {server_ip}:{server_port} via proxy {proxy_ip}:{proxy_port}")
try:
# Setup SOCKS5 proxy
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, proxy_ip, proxy_port)
socket.socket = socks.socksocket
# Ping the server
start_time = time.time()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
sock.connect((server_ip, server_port))
end_time = time.time()
response_time = round((end_time - start_time) * 1000, 2) # in milliseconds
print(f"Ping successful! Response time: {response_time}ms")
except socket.error as error:
print(f"Ping failed! Error: {error}")
finally:
sock.close()
print() # Add a newline for clarity
# Add a delay between pings to avoid overloading the server
time.sleep(1)
# Usage example
server_ip = 'your_minecraft_server_ip'
server_port = 25565
proxy_list_file = 'socks5_proxies.txt' # Replace with your proxy list file
ping_minecraft_server(server_ip, server_port, proxy_list_file)