You are on page 1of 8

CREATE A PYTHON

SERVER AND CAPTURE A


TCP HANDSHAKE WITH
WIRESHARK

Cameron W
Contents

Synopsis...........................................................................................................................................3

Response..........................................................................................................................................3

Wireshark Screenshot......................................................................................................................4

Code.................................................................................................................................................5

Client.py.......................................................................................................................................5

Server.py......................................................................................................................................6

References........................................................................................................................................8
Synopsis

Before starting the activity listed above, you will create a multi-threaded TCP server in Python
that can receive up to five simultaneous connections. Write a TCP client and try connecting more
than five instances of that client to your server. Capture and analyze the traffic using Wireshark.
In a Word document, include your code, screenshots of the Wireshark traffic, and a paragraph
explaining what happens when more than five clients try to connect to the server. Submit this
Word document along with your Hands-On Assignment to the assignment link above.

Response

After finishing my code and attempting to capture the traffic with Wireshark, I assume the server
I had written was more complicated than needed. After having over 100 connections, I
experimented with keeping the connections open to see failure possibly. After many
manipulations of server.py and client.py, the best I could find was a possible error saying TCP
ACKed unseen segment. I assumed that this is probably not what was indented from doing this
expertise and more so a failure in the connection. Obvious syn ack or syn failure as if it can only
accept five connections it should show in Wireshark a problem.
Wireshark Screenshot
Code

Client.py

# Client
import socket
import sys

#while 5:
s = socket.socket()
host = socket.gethostname()
port = 8888

s.connect((host,port))
print s.recv(1024)

#s.close
Server.py

# Server

import socket
import sys
from _thread import *

host = ''
port = 8888

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

print("Socket Created")

try:
s.bind((host,port))
except socket.error:
print("Binding Failed")
sys.exit()

print("Sock has been bounded")

s.listen(5)

print("Socket is Ready")

def clientthread(conn):
welcome = "welcome to the server. type something and hit enter"
conn.send(welcome.encode())

while True:
data = conn.recv(1024)
reply = "OK." + data.decode()
if not data:
break
print(reply)
conn.sendall(data.encode())

conn.close()

#conn,addr = s.accept()
#print("Connected with " + addr[0] + ":" + str(addr[1]))

while 1:
conn,addr = s.accept()
print("Connected with " + addr[0] + ":" + str(addr[1]))
start_new_thread(clientthread, (conn,))

#data = conn.recv(1024)
#print("OK. " + data.decode())
#if not data:
# break
#conn.sendall(data)

s.close()
References

Mellark (August 16, 2017). How To Create a Server - Python Networking Using TCP -
S01E03. Retrieved on October 1, 2018, from https://www.youtube.com/watch?v=s9pyrzr3IxQ

Mellark (August 16, 2017). How To Create a Multithreaded Server and Allow Many
Clients - Python Networking Using TCP - S01E05. Retrieved on October 1, 2018, from
https://www.youtube.com/watch?v=ZwxTGGEx-1w

The Pentamollis Project (Jun 4, 2016). Python Networking: TCP socket tutorial | Client
and Server model using python. Retrieved on October 1, 2018, from
https://www.youtube.com/watch?v=SepyXsvWVfo

You might also like