custom command check
This commit is contained in:
1 parent
e3d1dbbbf1
commit
4ccec278bf
3 files changed
+7
-39
No files matched your search
+5
-4
@@ -1,4 +1,4 @@
|
|||||||
# client.py
|
#!/usr/bin/env python3
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
PORT = 5055
|
PORT = 5055
|
||||||
@@ -15,14 +15,14 @@ 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("ls -la".encode())
|
client_socket.sendall(cmd.encode())
|
||||||
data = client_socket.recv(65536)
|
data = client_socket.recv(65536)
|
||||||
print("Received:", data.decode())
|
print("Received:", data.decode())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -30,4 +30,5 @@ def grep_all_ips(ips):
|
|||||||
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)
|
||||||
@@ -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)
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
chmod +x grepp.py
|
chmod +x ../client.py
|
||||||
mkdir -p ~/bin
|
mkdir -p ~/bin
|
||||||
cp grepp.py ~/bin/grepp
|
cp ../client.py ~/bin/grepp
|
||||||
chmod +x ~/bin/grepp
|
chmod +x ~/bin/grepp
|
||||||
export PATH="$HOME/bin:$PATH" > ~/.bashrc
|
export PATH="$HOME/bin:$PATH" > ~/.bashrc
|
||||||
source ~/.bashrc
|
source ~/.bashrc
|
||||||
Reference in new issue
Block a user