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
+23 -13

No files matched your search

+7 -6
View File
@@ -1,7 +1,7 @@
# client.py
#!/usr/bin/env python3
import socket
PORT = 5000
PORT = 5055
ALL_IPS = [
"172.22.156.3",
"172.22.158.2",
@@ -15,19 +15,20 @@ ALL_IPS = [
"172.22.156.6"
]
def grep_all_ips(ips):
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(b"Hello from client!")
data = client_socket.recv(1024)
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()
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
+10 -7
View File
@@ -1,25 +1,28 @@
# server.py
import socket
import shlex
import subprocess
HOST = "0.0.0.0"
PORT = 5000
PORT = 5055
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((HOST, PORT))
server_socket.listen()
print(f"Server listening on {HOST}:{PORT}")
# print(f"Server listening on {HOST}:{PORT}")
while True:
conn, addr = server_socket.accept()
print(f"Connected by {addr}")
# print(f"Connected by {addr}")
data = conn.recv(1024)
print("Received:", data.decode())
command = conn.recv(65536)
# print("Received Grep Command:", command.decode())
result = subprocess.run(shlex.split(command.decode()), capture_output=True, text=True)
conn.sendall(result.stdout.encode())
conn.sendall(b"Hello from server!")
conn.close()
server_socket.close()