wooly-vault/solutions/2.py

33 lines
602 B
Python
Raw Permalink Normal View History

2024-09-06 23:55:31 +02:00
from io import BufferedRWPair
import socket
REMOTE = "127.0.0.1"
PORT = 1337
def main() -> int:
s = socket.socket()
s.connect((REMOTE, PORT))
sf: BufferedRWPair = s.makefile('rwb')
pl = int.to_bytes(1337, 2, "big")
_ = send(sf, pl)
sf.close()
return 0
def send(sf: BufferedRWPair, msg: bytes) -> int:
print(f"> {msg.hex()}")
sent: int = sf.write(msg + b"\n")
sf.flush()
return sent
def recv(sf: BufferedRWPair) -> bytes:
response = sf.readline().strip()
print(f"< {response}")
return response
if __name__ == "__main__":
exit(main())