Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import binascii
- HOST = "0.0.0.0"
- PORT = 10012
- BUFFER_SIZE = 4096
- def hexdump(data, width=16):
- for i in range(0, len(data), width):
- chunk = data[i:i+width]
- hex_bytes = " ".join(f"{b:02X}" for b in chunk)
- ascii_bytes = "".join(chr(b) if 32 <= b <= 126 else "." for b in chunk)
- print(f"{i:04X} {hex_bytes:<{width*3}} {ascii_bytes}")
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
- s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- s.bind((HOST, PORT))
- s.listen()
- print(f"[+] Listening on {HOST}:{PORT}")
- conn, addr = s.accept()
- with conn:
- print(f"[+] Connection from {addr}")
- while True:
- data = conn.recv(BUFFER_SIZE)
- if not data:
- print("[-] Connection closed")
- break
- print(f"\n[+] Received {len(data)} bytes")
- print("Raw repr:")
- print(repr(data))
- print("\nHex dump:")
- hexdump(data)
Advertisement
Add Comment
Please, Sign In to add comment