Files
fa26_cs425_.group-mp_.team-01/MP1/client.py
T
2026-09-09 01:27:55 -05:00

34 lines
873 B
Python

#!/usr/bin/env python3
import socket
PORT = 5055
ALL_IPS = [
"172.22.156.3",
"172.22.158.2",
"172.22.94.2",
"172.22.156.4",
"172.22.158.3",
"172.22.94.3",
"172.22.156.5",
"172.22.158.4",
"172.22.94.4",
"172.22.156.6"
]
def grep_all_ips(ips, cmd):
for ip in ips:
try:
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((ip, PORT))
print(f"Connected to server at {ip}:{PORT}")
client_socket.sendall(cmd.encode())
data = client_socket.recv(65536)
print("Received:", data.decode())
except Exception as e:
print(f"Failed to connect to {ip}:{PORT} - {e}")
finally:
client_socket.close()
cmd = input("Enter the command to execute on all servers: ")
grep_all_ips(ALL_IPS, cmd)