Question: Converting and Logging Network Binary Data to Human Readable Format Do the following: Update the code from Part 1 to convert the output to human-readable
Converting and Logging Network Binary Data to Human Readable Format
Do the following:
- Update the code from Part 1 to convert the output to human-readable format.
- Update the code to save the output to a log file called networktraffic.log.
Part 1 Code
import socket
# the public network interface
HOST = socket.gethostbyname(socket.gethostname())
# A raw socket and bind it to the public interface
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
s.bind((HOST, 0))
# Include IP headers
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
# receive all packages
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
# receive a package
print(s.recvfrom(65565))
# disabled promiscuous mode
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)
Output Part 1
(b'E\x00\x00\xc8\xde|\x00\x00\xff\x11\xd1\xf2 \x00\x00\xb6\xff\xff\xff\xff\xc0\x02\x1a \x00\xb4\xee\xdf\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x9c\x00\x00\x00\x00{"ip":"10.0.0.182","gwId":"10024200b4e62d51d062","active":2,"ability":0,"mode":0,"encrypt":true,"productKey":"66mNaBqLdsYhX5lA","version":"3.1"}\xd9\xe4\xca\x16\x00\x00\xaaU', ('10.0.0.182', 0))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
