Moving on to the practical

First, we will make a server-side program that offers a connection to the client and sends a message to the client. Run

import socket
host = "" #Server address
port = 12345  #Port of Server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host,port)) #bind server 
conn, addr = s.accept()  
print addr, "Now Connected"
conn.send("Thank you for connecting")

The preceding code is very simple; it is minimal code on the server side.

First, import the socket module and define the host and port number, is the server's IP address. Socket.AF_INET defines the IPv4 protocol's family. Socket.SOCK_STREAM defines the TCP connection. The s.bind((host,port)) statement ...

Get Python Penetration Testing Essentials now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.