intern python task
intern python task
import struct
import textwrap
def main():
# Create a raw socket to capture network traffic
conn = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(3))
while True:
raw_data, addr = conn.recvfrom(65536)
dest_mac, src_mac, eth_proto, data = ethernet_frame(raw_data)
print("\nEthernet Frame:")
print(f"Destination: {dest_mac}, Source: {src_mac}, Protocol: {eth_proto}")
else:
print("Other IPv4 Data:")
print(format_multi_line(data))
def get_mac_addr(bytes_addr):
bytes_str = map('{:02x}'.format, bytes_addr)
return ':'.join(bytes_str).upper()
def ipv4(addr):
return '.'.join(map(str, addr))
if __name__ == "__main__":
main()