55 lines
1.5 KiB
Python
55 lines
1.5 KiB
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):
|
|
match_count = []
|
|
|
|
for i, ip in enumerate(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}")
|
|
|
|
full_cmd = cmd + f" ./machine.{i + 1}.log"
|
|
|
|
client_socket.sendall(full_cmd.encode())
|
|
data = client_socket.recv(65536).decode()
|
|
|
|
count = len(data.splitlines())
|
|
match_count.append(count)
|
|
if count > 0:
|
|
print(f"Filename: machine.{i + 1}.log")
|
|
print(f"Matches: {count}")
|
|
print(data)
|
|
|
|
except Exception as e:
|
|
print(f"Failed to connect to {ip}:{PORT} - {e}")
|
|
finally:
|
|
client_socket.close()
|
|
|
|
return match_count
|
|
|
|
while True:
|
|
cmd = input(">> ").strip()
|
|
match_count = grep_all_ips(ALL_IPS, cmd)
|
|
|
|
print("=========================== SUMMARY ===========================")
|
|
for i, count in enumerate(match_count):
|
|
if count > 0:
|
|
print(f"machine.{i + 1}.log: {count} matches")
|
|
print(f"Total matches: {sum(match_count)}")
|
|
print("===============================================================") |