Create function to connect to every server socket.

This commit is contained in:
jouya committed 2026-09-08 17:47:06 -05:00
1 parent 527ff24d64
commit b57d50e7b0
3 files changed
+25 -19

No files matched your search

+22 -5
View File
@@ -1,16 +1,33 @@
# client.py
import socket
HOST = "127.0.0.1"
PORT = 5000
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((HOST, PORT))
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)
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)
-13
View File
@@ -1,13 +0,0 @@
PORT=5000
IP1=172.22.156.3
IP2=172.22.158.2
IP3=172.22.94.2
IP4=172.22.156.4
IP5=172.22.158.3
IP6=172.22.94.3
IP7=172.22.156.5
IP8=172.22.158.4
IP9=172.22.94.4
IP10=172.22.156.6
+3 -1
View File
@@ -1,7 +1,7 @@
# server.py
import socket
HOST = "127.0.0.1"
HOST = "0.0.0.0"
PORT = 5000
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -11,6 +11,7 @@ server_socket.listen()
print(f"Server listening on {HOST}:{PORT}")
while True:
conn, addr = server_socket.accept()
print(f"Connected by {addr}")
@@ -20,4 +21,5 @@ print("Received:", data.decode())
conn.sendall(b"Hello from server!")
conn.close()
server_socket.close()