Merge pull request #1 from illinois-cs-coursework/aryan

tests
This commit is contained in:
Aryan Singh authored and GitHub committed 2026-09-10 13:44:14 -05:00 Unverified
commit fdb0532e44
3 files changed
+22 -12

No files matched your search

+7 -6
View File
@@ -1,7 +1,7 @@
# client.py #!/usr/bin/env python3
import socket import socket
PORT = 5000 PORT = 5055
ALL_IPS = [ ALL_IPS = [
"172.22.156.3", "172.22.156.3",
"172.22.158.2", "172.22.158.2",
@@ -15,19 +15,20 @@ ALL_IPS = [
"172.22.156.6" "172.22.156.6"
] ]
def grep_all_ips(ips): def grep_all_ips(ips, cmd):
for ip in ips: for ip in ips:
try: try:
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((ip, PORT)) client_socket.connect((ip, PORT))
print(f"Connected to server at {ip}:{PORT}") print(f"Connected to server at {ip}:{PORT}")
client_socket.sendall(b"Hello from client!") client_socket.sendall(cmd.encode())
data = client_socket.recv(1024) data = client_socket.recv(65536)
print("Received:", data.decode()) print("Received:", data.decode())
except Exception as e: except Exception as e:
print(f"Failed to connect to {ip}:{PORT} - {e}") print(f"Failed to connect to {ip}:{PORT} - {e}")
finally: finally:
client_socket.close() client_socket.close()
grep_all_ips(ALL_IPS) cmd = input("Enter the command to execute on all servers: ")
grep_all_ips(ALL_IPS, cmd)
+6
View File
@@ -0,0 +1,6 @@
chmod +x ../client.py
mkdir -p ~/bin
cp ../client.py ~/bin/grepp
chmod +x ~/bin/grepp
export PATH="$HOME/bin:$PATH" > ~/.bashrc
source ~/.bashrc
+9 -6
View File
@@ -1,24 +1,27 @@
# server.py # server.py
import socket import socket
import shlex
import subprocess
HOST = "0.0.0.0" HOST = "0.0.0.0"
PORT = 5000 PORT = 5055
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((HOST, PORT)) server_socket.bind((HOST, PORT))
server_socket.listen() server_socket.listen()
print(f"Server listening on {HOST}:{PORT}") # print(f"Server listening on {HOST}:{PORT}")
while True: while True:
conn, addr = server_socket.accept() conn, addr = server_socket.accept()
print(f"Connected by {addr}") # print(f"Connected by {addr}")
data = conn.recv(1024) command = conn.recv(65536)
print("Received:", data.decode()) # print("Received Grep Command:", command.decode())
conn.sendall(b"Hello from server!") result = subprocess.run(shlex.split(command.decode()), capture_output=True, text=True)
conn.sendall(result.stdout.encode())
conn.close() conn.close()