Question: This week, you are going to build on the program from last week. Use the same file from last week. You will be extracting the

This week, you are going to build on the program from last week. Use the same file from last week. You will be extracting the first partition entry from the master boot record that is contained in the file. The first partition entry starts at offset 0x1BE and ends at 0x1CD. Pull that chunk of bytes out of the file provided and send it to the server software that you will write. The server will listen for the chunk of data and print out the status of the drive, the partition type and the starting address of the partition as an integer.

You can refer to Wikipedia (Links to an external site.) for additional details about offsets within the master boot record and partition table for the pieces of information you are looking for.

client side code:

import socket # Import socket module import struct s = socket.socket() # Create a socket object host = socket.gethostname() # Get local machine name port = 12345 # Reserve a port for your service. s.connect((host, port)) print(s.recv(2048)) # open the master boot record file called block.dd and save into an array f = open("block.dd", "rb") mbr = bytearray() # this opens the array and closes the file when done try: mbr = f.read(2048) s.send(mbr) finally: f.close() status = mbr[0x1BE] class Status(object): pass if status == 0x80: print("Status: Active") s.sendall(b'Status: Active') else: print("Status: Not active") s.sendall(b"Status: Not Active") # this looks at the partition type (1 byte located at the address 1BE + 4) and prints it out ptype = mbr[0x1BE + 4] print("Partition type: ", ptype) s.send(b'ptype') # this looks at the address of the first sector in the partition (1BE + 8) and prints it out addr = struct.unpack("

sever side code:

import socket # Import socket module s = socket.socket() # Create a socket object host = socket.gethostname() # Get local machine name port = 12345 # Reserve a port for your service. s.bind((host, port)) # Bind to the port len = 2048 s.listen(5) # Now wait for client connection. while True: c, addr = s.accept() # Establish connection with client. print('Got connection from', addr) c.send(b'Thank you for connecting') while 1: data = c.recv(len) if data: print(data) s.close() 

output from client side:

b'Thank you for connecting' Status: Active Partition type: 131 Address of the first sector in the partition: 2048

Process finished with exit code 0

Output from server side:

Got connection from ('192.168.10.12', 50433) b'\xebc\x90\x10\x8e\xd0\xbc\x00\xb0\xb8\x00\x00\x8e\xd8\x8e\xc0\xfb\xbe\x00|\xbf\x00\x06\xb9\x00\x02\xf3\xa4\xea!\x06\x00\x00\xbe\xbe\x078\x04u\x0b\x83\xc6\x10\x81\xfe\xfe\x07u\xf3\xeb\x16\xb4\x02\xb0\x01\xbb\x00|\xb2\x80\x8at\x01\x8bL\x02\xcd\x13\xea\x00|\x00\x00\xeb\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x01\x00\x00\x00\x00\x00\x00\x00\xff\xfa\x90\x90\xf6\xc2\x80t\x05\xf6\xc2pt\x02\xb2\x80\xeay|\x00\x001\xc0\x8e\xd8\x8e\xd0\xbc\x00 \xfb\xa0d|<\xfft\x02\x88\xc2R\xbb\x17\x04\xf6\x07\x03t\x06\xbe\x88}\xe8\x17\x01\xbe\x05|\xb4A\xbb\xaaU\xcd\x13ZRr=\x81\xfbU\xaau7\x83\xe1\x01t21\xc0\x89D\x04@\x88D\xff\x89D\x02\xc7\x04\x10\x00f\x8b\x1e\\|f\x89\\\x08f\x8b\x1e`|f\x89\\\x0c\xc7D\x06\x00p\xb4B\xcd\x13r\x05\xbb\x00p\xebv\xb4\x08\xcd\x13s Z\x84\xd2\x0f\x83\xd0\x00\xbe\x93}\xe9\x82\x00f\x0f\xb6\xc6\x88d\xff@f\x89D\x04\x0f\xb6\xd1\xc1\xe2\x02\x88\xe8\x88\xf4@\x89D\x08\x0f\xb6\xc2\xc0\xe8\x02f\x89\x04f\xa1`|f\t\xc0uNf\xa1\\|f1\xd2f\xf74\x88\xd11\xd2f\xf7t\x04;D\x08}7\xfe\xc1\x88\xc50\xc0\xc1\xe8\x02\x08\xc1\x88\xd0Z\x88\xc6\xbb\x00p\x8e\xc31\xdb\xb8\x01\x02\xcd\x13r\x1e\x8c\xc3`\x1e\xb9\x00\x01\x8e\xdb1\xf6\xbf\x00\x80\x8e\xc6\xfc\xf3\xa5\x1fa\xff&Z|\xbe\x8e}\xeb\x03\xbe\x9d}\xe84\x00\xbe\xa2}\xe8.\x00\xcd\x18\xeb\xfeGRUB \x00Geom\x00Hard Disk\x00Read\x00 Error \x00\xbb\x01\x00\xb4\x0e\xcd\x10\xac<\x00u\xf4\xc3\x19\xd7\xc8\xfb\x00\x00\x80 !\x00\x83\xfe\xff\xff\x00\x08\x00\x00\x00hd\x02\x00\xfe\xff\xff\x05\xfe\xff\xff\xfewd\x02\x02\x80\x1b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00U\xaaR\xe8(\x01t\x08V\xbe3\x81\xe8L\x01^\xbf\xf4\x81f\x8b-\x83}\x08\x00\x0f\x84\xe9\x00\x80|\xff\x00tFf\x8b\x1df\x8bM\x04f1\xc0\xb0\x7f9E\x08\x7f\x03\x8bE\x08)E\x08f\x01\x05f\x83U\x04\x00\xc7\x04\x10\x00\x89D\x02f\x89\\\x08f\x89L\x0c\xc7D\x06\x00pP\xc7D\x04\x00\x00\xb4B\xcd\x13\x0f\x82\xbb\x00\xbb\x00p\xebhf\x8bE\x04f\t\xc0\x0f\x85\xa3\x00f\x8b\x05f1\xd2f\xf74\x88T f1\xd2f\xf7t\x04\x88T\x0b\x89D\x0c;D\x08\x0f\x8d\x83\x00\x8b\x04*D 9E\x08\x7f\x03\x8bE\x08)E\x08f\x01\x05f\x83U\x04\x00\x8aT \xc0\xe2\x06\x8aL \xfe\xc1\x08\xd1\x8al\x0cZR\x8at\x0bP\xbb\x00p\x8e\xc31\xdb\xb4\x02\xcd\x13rP\x8c\xc3\x8eE X\xc1\xe0\x05\x01E `\x1e\xc1\xe0\x03\x89\xc11\xff1\xf6\x8e\xdb\xfc\xf3\xa5\x1f\xe8>\x00t\x06\xbe;\x81\xe8c\x00a\x83}\x08\x00\x0f\x85\x1d\xff\x83\xef\x0c\xe9\x0f\xff\xe8$\x00t\x06\xbe=\x81\xe8I\x00Z\xea\x00\x82\x00\x00\xbe@\x81\xe8=\x00\xeb\x06\xbeE\x81\xe85\x00\xbeJ\x81\xe8/\x00\xeb\xfe\xbb\x17\x04\xf6\x07\x03\xc3loading\x00.\x00 \x00Geom\x00Read\x00 Error\x00\xbb\x01\x00\xb4\x0e\xcd\x10F\x8a\x04<\x00u\xf2\xc3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00c\x00 \x08' b'Status: Active' b'ptype' b'(int(addr[0], 0))'

I am suppose to be sending and receiving information. My problem is that when I send 'ptype' and 'int(addr[0[, 0' to the server, it sends what I wrote, not the data associated with it. So my server side is printing out unreadable data and the literal things I wrote, not the data associated with it. How do I fix this?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!