From 6591589b77fc7999cbb204ccf541837cfbf69e5e Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Wed, 9 Sep 2026 00:42:00 -0500 Subject: [PATCH 01/10] Update server.py --- MP1/server.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/MP1/server.py b/MP1/server.py index 7ec1143..db7d158 100644 --- a/MP1/server.py +++ b/MP1/server.py @@ -1,5 +1,6 @@ # server.py import socket +import subprocess HOST = "0.0.0.0" PORT = 5000 @@ -15,11 +16,12 @@ while True: conn, addr = server_socket.accept() print(f"Connected by {addr}") - data = conn.recv(1024) - print("Received:", data.decode()) + command = conn.recv(1024) + print("Received Grep Command:", command.decode()) + + result = subprocess.run(command.decode(), capture_output=True, text=True) + conn.sendall(result.stdout.encode()) - conn.sendall(b"Hello from server!") - conn.close() server_socket.close() \ No newline at end of file From cbb1881024982c29f239d185ea6b06d3e3692785 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Wed, 9 Sep 2026 00:42:41 -0500 Subject: [PATCH 02/10] Update client.py --- MP1/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MP1/client.py b/MP1/client.py index f462612..c34640f 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -22,7 +22,7 @@ def grep_all_ips(ips): client_socket.connect((ip, PORT)) print(f"Connected to server at {ip}:{PORT}") - client_socket.sendall(b"Hello from client!") + client_socket.sendall("echo hello".encode()) data = client_socket.recv(1024) print("Received:", data.decode()) except Exception as e: From eb802908680e69b4a51f010ed473aba5481c80e5 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Wed, 9 Sep 2026 00:50:51 -0500 Subject: [PATCH 03/10] Update server.py --- MP1/server.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MP1/server.py b/MP1/server.py index db7d158..dba9369 100644 --- a/MP1/server.py +++ b/MP1/server.py @@ -10,14 +10,14 @@ 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}") command = conn.recv(1024) - print("Received Grep Command:", command.decode()) + # print("Received Grep Command:", command.decode()) result = subprocess.run(command.decode(), capture_output=True, text=True) conn.sendall(result.stdout.encode()) From 7c63617d85146ad46d0be29a37c4510431e9da36 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Wed, 9 Sep 2026 00:57:08 -0500 Subject: [PATCH 04/10] Update client.py --- MP1/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MP1/client.py b/MP1/client.py index c34640f..bc9721b 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -22,7 +22,7 @@ def grep_all_ips(ips): client_socket.connect((ip, PORT)) print(f"Connected to server at {ip}:{PORT}") - client_socket.sendall("echo hello".encode()) + client_socket.sendall("ls -la".encode()) data = client_socket.recv(1024) print("Received:", data.decode()) except Exception as e: From 4c19b6b053306e938951095fb2ac6b38ea9cfa38 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Wed, 9 Sep 2026 00:57:59 -0500 Subject: [PATCH 05/10] buffer size update --- MP1/client.py | 2 +- MP1/server.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MP1/client.py b/MP1/client.py index bc9721b..6f50103 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -23,7 +23,7 @@ def grep_all_ips(ips): print(f"Connected to server at {ip}:{PORT}") client_socket.sendall("ls -la".encode()) - data = client_socket.recv(1024) + data = client_socket.recv(65536) print("Received:", data.decode()) except Exception as e: print(f"Failed to connect to {ip}:{PORT} - {e}") diff --git a/MP1/server.py b/MP1/server.py index dba9369..199b93b 100644 --- a/MP1/server.py +++ b/MP1/server.py @@ -16,7 +16,7 @@ while True: conn, addr = server_socket.accept() # print(f"Connected by {addr}") - command = conn.recv(1024) + command = conn.recv(65536) # print("Received Grep Command:", command.decode()) result = subprocess.run(command.decode(), capture_output=True, text=True) From ed5689fb5a1c89575f01bb1d1a52829dd58992ce Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Wed, 9 Sep 2026 01:06:03 -0500 Subject: [PATCH 06/10] Update server.py --- MP1/server.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MP1/server.py b/MP1/server.py index 199b93b..c2a0c2e 100644 --- a/MP1/server.py +++ b/MP1/server.py @@ -1,9 +1,10 @@ # 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) @@ -19,7 +20,7 @@ while True: command = conn.recv(65536) # print("Received Grep Command:", command.decode()) - result = subprocess.run(command.decode(), capture_output=True, text=True) + result = subprocess.run(shlex.split(command.decode()), capture_output=True, text=True) conn.sendall(result.stdout.encode()) conn.close() From 69974badd019fd9802a3a888cdd721dd76fed735 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Wed, 9 Sep 2026 01:12:56 -0500 Subject: [PATCH 07/10] Update client.py --- MP1/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MP1/client.py b/MP1/client.py index 6f50103..b75106b 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -1,7 +1,7 @@ # client.py import socket -PORT = 5000 +PORT = 5055 ALL_IPS = [ "172.22.156.3", "172.22.158.2", From 13799144cb8c0166435f150caa7f7fa8f59232ef Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Wed, 9 Sep 2026 01:21:49 -0500 Subject: [PATCH 08/10] trying out custom command --- MP1/scripts/grepp.py | 33 +++++++++++++++++++++++++++++++++ MP1/scripts/install_cmd.sh | 6 ++++++ 2 files changed, 39 insertions(+) create mode 100644 MP1/scripts/grepp.py create mode 100644 MP1/scripts/install_cmd.sh diff --git a/MP1/scripts/grepp.py b/MP1/scripts/grepp.py new file mode 100644 index 0000000..01656c2 --- /dev/null +++ b/MP1/scripts/grepp.py @@ -0,0 +1,33 @@ +#!/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): + 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("ls -la".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) \ No newline at end of file diff --git a/MP1/scripts/install_cmd.sh b/MP1/scripts/install_cmd.sh new file mode 100644 index 0000000..c9f9224 --- /dev/null +++ b/MP1/scripts/install_cmd.sh @@ -0,0 +1,6 @@ +chmod +x grepp.py +mkidr -p ~/bin +cp grepp.py ~/bin/grepp +chmod +x ~/bin/grepp +export PATH="$HOME/bin:$PATH" +course ~/.bashrc \ No newline at end of file From e3d1dbbbf1a84ba10d8f99c9d62a076cf9590746 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Wed, 9 Sep 2026 01:24:03 -0500 Subject: [PATCH 09/10] Update install_cmd.sh --- MP1/scripts/install_cmd.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MP1/scripts/install_cmd.sh b/MP1/scripts/install_cmd.sh index c9f9224..49a8307 100644 --- a/MP1/scripts/install_cmd.sh +++ b/MP1/scripts/install_cmd.sh @@ -1,6 +1,6 @@ chmod +x grepp.py -mkidr -p ~/bin +mkdir -p ~/bin cp grepp.py ~/bin/grepp chmod +x ~/bin/grepp -export PATH="$HOME/bin:$PATH" -course ~/.bashrc \ No newline at end of file +export PATH="$HOME/bin:$PATH" > ~/.bashrc +source ~/.bashrc \ No newline at end of file From 4ccec278bf27b4f06087495feebcc430634edf7c Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Wed, 9 Sep 2026 01:27:55 -0500 Subject: [PATCH 10/10] custom command check --- MP1/client.py | 9 +++++---- MP1/scripts/grepp.py | 33 --------------------------------- MP1/scripts/install_cmd.sh | 4 ++-- 3 files changed, 7 insertions(+), 39 deletions(-) delete mode 100644 MP1/scripts/grepp.py diff --git a/MP1/client.py b/MP1/client.py index b75106b..c37f832 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -1,4 +1,4 @@ -# client.py +#!/usr/bin/env python3 import socket PORT = 5055 @@ -15,14 +15,14 @@ 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("ls -la".encode()) + client_socket.sendall(cmd.encode()) data = client_socket.recv(65536) print("Received:", data.decode()) except Exception as e: @@ -30,4 +30,5 @@ def grep_all_ips(ips): finally: client_socket.close() -grep_all_ips(ALL_IPS) \ No newline at end of file +cmd = input("Enter the command to execute on all servers: ") +grep_all_ips(ALL_IPS, cmd) \ No newline at end of file diff --git a/MP1/scripts/grepp.py b/MP1/scripts/grepp.py deleted file mode 100644 index 01656c2..0000000 --- a/MP1/scripts/grepp.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/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): - 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("ls -la".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) \ No newline at end of file diff --git a/MP1/scripts/install_cmd.sh b/MP1/scripts/install_cmd.sh index 49a8307..34a5f30 100644 --- a/MP1/scripts/install_cmd.sh +++ b/MP1/scripts/install_cmd.sh @@ -1,6 +1,6 @@ -chmod +x grepp.py +chmod +x ../client.py mkdir -p ~/bin -cp grepp.py ~/bin/grepp +cp ../client.py ~/bin/grepp chmod +x ~/bin/grepp export PATH="$HOME/bin:$PATH" > ~/.bashrc source ~/.bashrc \ No newline at end of file