Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CAN I PLEASE GET HELP WITH THIS? I AM WRITING CODE FOR A PYTHON CLIENT. PLEASE HELP!!! MY CODE SO FAR ********LIGHTCLIENT.PY****** import socket import

CAN I PLEASE GET HELP WITH THIS? I AM WRITING CODE FOR A PYTHON CLIENT. PLEASE HELP!!!

image text in transcribed

image text in transcribed

MY CODE SO FAR

********LIGHTCLIENT.PY******

import socket import argparse import struct import binascii

#------------------------------------------------------------------------------- #Arguments parser = argparse.ArgumentParser(description='Client Options') parser.add_argument('-p', '--port', type=int, metavar='', help='Port to be used to send message') parser.add_argument('-s', '--server', type=str, metavar='', help='IP Address of server')

args = parser.parse_args()

#------------------------------------------------------------------------------- #Socket information #-------------------------------------------------------------------------------

hostName = socket.gethostname() REMOTE_ADDR = args.server REMOTE_PORT = args.port SERVER_ADDR = (REMOTE_ADDR, REMOTE_PORT) ENCODING = 'utf-8'

#------------------------------------------------------------------------------- #Creating Struct Packets #-------------------------------------------------------------------------------

values = (17, 1, 1280, 'Hello'.encode('utf-8')) s = struct.Struct('I I I 5s') packed = s.pack(*values)

values2 = (17, 2, 1792, 'Hello'.encode('utf-8')) s2 = struct.Struct('I I I 5s') packed2 = s2.pack(*values2)

#------------------------------------------------------------------------------- #Establishing connections and sending packets and printing results #------------------------------------------------------------------------------- global count count = 0

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.connect(SERVER_ADDR)

#First Packet sent client.send(packed) print("Sending HELLO Packet")

from_server = client.recv(64).decode('utf-8') print(from_server) from_server = client.recv(64).decode('utf-8') print(from_server) if from_server == 'VERSION ACCEPTED': print("Received Message Hello") print("Sending Command") count = count + 1 client.close()

client2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client2.connect(SERVER_ADDR)

#Second Packet sent client2.send(packed2)

from_server = client2.recv(64).decode('utf-8') print(from_server) from_server = client2.recv(64).decode('utf-8') print(from_server)

if from_server == 'VERSION ACCEPTED': count = count + 1

if count == 2: print("Received Message SUCCESS") print("Command Successful")

client2.close() print("Closing Socket")

$ lightclient -5 -P -1 LOGFILE The client takes three arguments: 1. Server IP - The IP address of the server. 2. PORT - The port the server listens on. 3. log file location - Where you will keep a record of packets you received. For example: $ lightclient -5 192.168.2.1 -p 6543 -1 LOGFILE 4. The client must parse three command line arguments, server, port, and logfile. 5. The client should connect to the server on the specified port. 6. Constructs and sends a hello packet to the server. 1 Version (4 bytes) Message type (4 bytes) | Message Length (4 bytes) | | 1 Message (HELLO) 7 Docavo Sonor VERSION ACCEPTED" olco log "VERSION MISMATCH" 7. Receive reply from Server - if version is 17, log "VERSION ACCEPTED", else log - "VERSION MISMATCH" 8. If version is accepted, send a command packet. 1 Version (4 bytes) Message type (4 bytes) | Message Length (4 bytes) | 1 1 COMMAND (LIGHTON/LIGHTOFF) 9. Receive the server's reply, log the reply, send a DISCONNECT message to the server, and shutdown the socket. You can assume the server always replies with a "SUCCESS" message for this assignment. 10. Use TCPDUMP or Wireshark to capture the interactions, turn the .pcap file in with the assignment. $ lightclient -5 -P -1 LOGFILE The client takes three arguments: 1. Server IP - The IP address of the server. 2. PORT - The port the server listens on. 3. log file location - Where you will keep a record of packets you received. For example: $ lightclient -5 192.168.2.1 -p 6543 -1 LOGFILE 4. The client must parse three command line arguments, server, port, and logfile. 5. The client should connect to the server on the specified port. 6. Constructs and sends a hello packet to the server. 1 Version (4 bytes) Message type (4 bytes) | Message Length (4 bytes) | | 1 Message (HELLO) 7 Docavo Sonor VERSION ACCEPTED" olco log "VERSION MISMATCH" 7. Receive reply from Server - if version is 17, log "VERSION ACCEPTED", else log - "VERSION MISMATCH" 8. If version is accepted, send a command packet. 1 Version (4 bytes) Message type (4 bytes) | Message Length (4 bytes) | 1 1 COMMAND (LIGHTON/LIGHTOFF) 9. Receive the server's reply, log the reply, send a DISCONNECT message to the server, and shutdown the socket. You can assume the server always replies with a "SUCCESS" message for this assignment. 10. Use TCPDUMP or Wireshark to capture the interactions, turn the .pcap file in with the assignment

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago