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.

tcpClient.py

import socket, sys

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

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

        clientSocket.connect((host, port))
        print("[+] Socket connected successfully to " + host + " on " + str(port) + "!\n")

    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.send(message.encode())
        data = clientSocket.recv(1024).decode()

        print(" (received message): " + data)

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

    clientSocket.close()

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