Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Session 03 - Python for Forensics

The code here is to support the Session 03 lecture.

udpClient.py

import socket, sys

def client():
    host = "127.0.0.1"
    port = 5000

    try:
        clientSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        print("[+] UDP socket successfully created!")

    except socket.error as error:
        print("[E] There was an issue with the socket, due to %s" %(error))
        print("[!] Exiting...")
        sys.exit()

    message = input(" (send message): ")

    while message.lower().strip() != 'bye':
        clientSocket.sendto(message.encode(), (host, port))
        message, addr = clientSocket.recvfrom(1024)
        print(" (received message): " + message.decode())

        message = input(" (send message): ")

    clientSocket.close()

if __name__ == '__main__':
    client()
[ Last updated: Tuesday 13 February 2024 @ 11:22:49 +0000 // branch: master // commit: bd41815 ]