Update Python Ofensivo - Pruebas de conexión con la librería socket

This commit is contained in:
2024-01-11 20:26:58 +01:00
parent 653e96cc2b
commit ec29b5cde0
4 changed files with 130 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
#!/usr/bin/env python3
"""
Server socket
"""
import socket
def start_server():
host = 'localhost'
port = 1234
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((host, port))
s.listen(1)
print(f"[*] Servidor en escucha en {host}:{port}")
conn, addr = s.accept()
print(f"[+] {addr} Conectado.")
with conn:
print(f"[*] Conexión establecida con {addr}")
while True:
data = conn.recv(1024)
if not data:
break
conn.sendall(data)
print(f"[i] Mensaje de {addr}:\n\t{data.decode()}")
conn.sendall(f"Ola k ase client!\n".encode())
start_server()