Class 6 Lab 2 ‐ Client Socket - Justin-Boyd/Python-Class GitHub Wiki

Step 1

  • Start the Kali Linux machine in Live mode.

Step 2

  • Open the terminal by clicking its icon in the options bar on the left side of the window.

Step 3

  • Run the command ip a to identify the IP address of the machine for future use.

Step 4

  • Use the command netcat -lvp 4444 to start a listener.

Step 5

  • Create a new Python file by right-clicking the project’s folder, and selecting New > Python File. Name the file Client.

Step 6

  • Import the socket module to the file.
import socket

Step 7

  • Import the time module to the file.
import time

Step 8

  • Create a socket variable.
my_sock = socket.socket()

Step 9

  • Connect the socket to the listener in the Kali machine.
my_sock.connect((“10.0.2.4”, 4444)) 

Step 10

  • Add a pause of 5 seconds after the connection using the time module.
time.sleep(5) 

Step 11

  • Close the connection at the end of the client’s script.
my_sock.close()

Step 12

  • Execute the code by right-clicking the file, and then clicking Run.

Step 13

  • Verify in the Kali machine that the connection was established.

Final Code

"""Lab Objective: Create a client socket."""
import socket
import time

my_socket = socket.socket()
my_socket.connect(("10.0.0.5", 4444))
time.sleep(5)
my_socket.close()

input("\nPress 'Enter' to exit the program")# prevents program from closing upon execution